PDA

View Full Version : Display sub-category Name in the Meta Description Tag.



PGGO
April 29, 2012, 01:13 AM
meta description tag: <meta name="description" content="" />

I want to add a single “meta description” to my Parent category and it should be displayed under all sub-categories as well, rather than add one by one for every sub-category (which is time consuming).

In addition, I want to include sub-category’s Names in the “meta description”, so it will look like the following:
View in Admin Panel (parent category): Local directories of [breed_name] cats for sale…
View in Web Browser (child category): Local directories of Russian Blue cats for sale…

Flynax is already having this option in the previous versions of classifieds (v3); however, it does not work anymore in version 4.

Please give some advice, how can I implement the same function in Flynax v4.
Thanks.

Viktor
May 5, 2012, 10:24 AM
Hello Petnax,


meta description tag: <meta name="description" content="" />
I want to add a single “meta description” to my Parent category and it should be displayed under all sub-categories as well, rather than add one by one for every sub-category (which is time consuming).
In addition, I want to include sub-category’s Names in the “meta description”, so it will look like the following:
Please go to ftp: includes/classes/rlCategories.class.php find getCategory function

after this code:

$category = $this -> rlLang -> replaceLangKeys( $category, 'categories', array( 'name', 'title', 'des', 'meta_description', 'meta_keywords' ) );

add:

if( empty($category['meta_description']) && empty($category['meta_keywords']))
{
$parent_category = $this -> fetch( array('ID', 'Key'), array('ID' => $category['Parent_ID']), $status, null, 'categories', 'row');

$parent_category = $this -> rlLang -> replaceLangKeys( $parent_category, 'categories', array( 'meta_description', 'meta_keywords' ) );

$category['meta_description'] = $parent_category['meta_description'];
$category['meta_keywords'] = $parent_category['meta_keywords'];
}



View in Admin Panel (parent category): Local directories of [breed_name] cats for sale…
View in Web Browser (child category): Local directories of Russian Blue cats for sale…
Flynax is already having this option in the previous versions of classifieds (v3); however, it does not work anymore in version 4.
Please give some advice, how can I implement the same function in Flynax v4.
Thanks.

I have checked it and I see New York >> Cats >> Russian Blue in front end. Would you please explain me what do you want instead of this?

PGGO
May 6, 2012, 03:21 AM
Hi Viktor,

Thanks for the code; it works!

However, all my sub-categories got the same meta-description now. It can hurt from SEO perspective.

Q: is it possible to include sub-category names in the meta-description of all sub-categories by using the same meta-d from Parent category?

Example:
Template of parent category meta-d: Local directory of {CATEGORY_NAME} cats and kittens for sale.

Parent category meta-d: Local directory of cats and kittens for sale.
1. Child category meta-d: Local directory of Sphynx cats and kittens for sale.
2. Child category meta-d: Local directory of Russian Blue cats and kittens for sale.
3. Child category meta-d: Local directory of Siamese cats and kittens for sale.
4. Etc.

The example above shows that we are using template meta-d which is located in Parent category; however, it has Names of sub-categories as well which are displayed under all sub-categories.

Viktor
May 7, 2012, 03:20 AM
Hello Petnax,

Please go to ftp: includes/classes/rlCategories.class.php find getCategory function
after this code:

if( empty($category['meta_description']) && empty($category['meta_keywords']))
{
$parent_category = $this -> fetch( array('ID', 'Key'), array('ID' => $category['Parent_ID']), $status, null, 'categories', 'row');

$parent_category = $this -> rlLang -> replaceLangKeys( $parent_category, 'categories', array( 'meta_description', 'meta_keywords' ) );

$category['meta_description'] = $parent_category['meta_description'];
$category['meta_keywords'] = $parent_category['meta_keywords'];
}

add:


$category['meta_description'] = str_replace('{CATEGORY_NAME}', $parent_category ? $category['name'] : '', $category['meta_description']);
$category['meta_keywords'] = str_replace('{CATEGORY_NAME}', $parent_category ? $category['name'] : '', $category['meta_keywords']);

And also in parent meta code add {CATEGORY_NAME} like you indicated in your example.

PGGO
May 7, 2012, 10:03 PM
It works!
Thank you.

PGGO
May 8, 2012, 11:52 PM
Viktor:

I’m trying to apply the same function to the TITLE tag; however, it does not work at all.

I used the following code:
$category['title'] = str_replace('{CATEGORY_NAME}', $parent_category ? $category['name'] : '', $category['title']);

Would you please give some recommendations?

Viktor
May 9, 2012, 04:46 AM
Hello Petnax,

It's not working because in title not exist '{CATEGORY_NAME}'. Would you please explain me what structure should be for sub categories title?

PGGO
May 9, 2012, 06:42 AM
I want to apply the same function as we did with meta-description for sub-categories.

Example:
Template of parent category TITLE: {CATEGORY_NAME} Cats & Kittens for Sale

Parent category TITLE: Cats & Kittens for Sale
1. Child category TITLE: Sphynx Cats & Kittens for Sale
2. Child category TITLE: Russian Blue Cats & Kittens for Sale
3. Child category TITLE: Siamese Cats & Kittens for Sale
4. Etc.

Viktor
May 10, 2012, 04:21 AM
Hello Petnax,

Please replace your getCategory function to:


function getCategory( $id = false, $path = false )
{
if ( !$id && !$path )
{
return false;
}

$this -> rlValid -> sql( $path );

if (defined('REALM') && REALM == 'admin')
{
$status = "AND `Status` <> 'trash'";
}
else
{
$status = "AND `Status` = 'active'";
}

if( $id )
{
$where['ID'] = (int)$id;
}
elseif ( $path )
{
$where['Path'] = $path;
}

$category = $this -> fetch( array( 'ID', 'Parent_ID', 'Path', 'Key', 'Count', 'Lock', 'Type', 'Level', 'Add'), $where, $status, null, 'categories', 'row' );
if ( empty($category) )
{
return false;
}
$category = $this -> rlLang -> replaceLangKeys( $category, 'categories', array( 'name', 'title', 'des', 'meta_description', 'meta_keywords' ) );
if($category['Level'] > 0)
{
$parent_category = $this -> fetch( array('ID', 'Key'), array('ID' => $category['Parent_ID']), $status, null, 'categories', 'row');
$parent_category = $this -> rlLang -> replaceLangKeys( $parent_category, 'categories', array( 'meta_description', 'meta_keywords', 'title' ) );
}

if( empty($category['meta_description']) && empty($category['meta_keywords']))
{
$category['meta_description'] = $parent_category['meta_description'];
$category['meta_keywords'] = $parent_category['meta_keywords'];
}
$category['meta_description'] = str_replace('{CATEGORY_NAME}', $parent_category ? $category['name'] : '', $category['meta_description']);
$category['meta_keywords'] = str_replace('{CATEGORY_NAME}', $parent_category ? $category['name'] : '', $category['meta_keywords']);
$category['title'] = str_replace('{CATEGORY_NAME}', $parent_category ? $parent_category['title'] : '', $category['title']);

return $category;
}

PGGO
May 10, 2012, 06:00 AM
Viktor:

I have replaced the code (getCategory function), but it still does not work for TITLE.
It works for meta-description and keywords, but not for a title tag.

Would you please check if there is an error in code that you provide?

Viktor
May 10, 2012, 10:19 AM
Hello Petnax,

Yes it's my mistake sorry.

Please find last line in new getCategory function:


$category['title'] = str_replace('{CATEGORY_NAME}', $parent_category ? $parent_category['title'] : '', $category['title']);

and replace to:


$category['title'] = $parent_category ? $category['title'] .' '. $parent_category['title'] : $category['title'];

PGGO
May 10, 2012, 09:13 PM
Viktor:

It still does not replace the {CATEGORY_NAME} for the Name of category in the TITLE of sub-categories.

Example:
my Parent category is “{CATEGORY_NAME} Cats & Kittens for Sale”
my Sub-category is stays the same “{CATEGORY_NAME} Cats & Kittens for Sale”

Viktor
May 11, 2012, 03:24 AM
Hello Petnax,

No needs {CATEGORY_NAME} for the title. System automatically will be append title from parent. I don't see any changes applied on your site. Did you remove it?

PGGO
May 11, 2012, 05:06 AM
Yes, I removed after the test.
The problem is that, the titles are become identical for parent and sub-categories.
Is it possible to do like with meta-description, so I can add only the Name of sub-category in the Title?

Viktor
May 11, 2012, 05:35 AM
Would you please create new ticket with this request and include ftp access details in. I check it.

Hareesh Ghanta
August 20, 2013, 02:03 AM
Hi Victor,
This is really great feature.I did not noticed till now.I tried with the same code you provided however Category Name is not displaying in meta description and keywords and Title.Could you please help me out.

Viktor
August 20, 2013, 06:59 AM
Hello Hareesh Ghanta.

Would you please send me PM with ftp access I should check it myself because I don't know exactly where is a problem.

Hareesh Ghanta
August 21, 2013, 12:51 AM
Hi Viktor,
Sent you details

Viktor
August 21, 2013, 06:51 AM
Hello Hareesh,

This customization a bit different that you want for you.

You added meta tag: '{CATEGORY_NAME} for {sale_rent} in {area} {states_level1}'

where {CATEGORY_NAME} it's parent category name but you added your text in parent category but should in child.
My code change only {CATEGORY_NAME} but you added more variables '{sale_rent} in {area} {states_level1}' system cannot change this variables to valid value because you should create a code for it.

Hareesh Ghanta
August 21, 2013, 11:11 AM
Hi Viktor,
Thank you for replying.I am looking for the meta like
{Subcategory name} for {sale_rent} in {City}
Apartment for rent in New york

When i view source on particular listing it is showing me For rent in New York with out showing the category Name.

Could you please help me how can i achieve this and which is best way for SEO purposes so that my each listing will have proper meta codes

Hareesh Ghanta
August 22, 2013, 11:53 PM
Hi Viktor,
I understand what you were referring to.Thank you. I would like to include the {Subcategory name} as listing metadata and keywords and Title.Is there any way we could do it?

Thank you.

Viktor
August 23, 2013, 08:29 AM
Yes you should include it in metadata and title and you should replace {Subcategory name} to real value in php.

Bratu Marius
October 28, 2013, 04:27 PM
Hi Viktor,

from SEO reasons,
we want to put custom title and meta description in the categories and subcategories pages.
I tried the code presented here and does not work

Can you help please

Thank you

Viktor
October 29, 2013, 09:42 AM
Hello Bratu,

Will be better if you create a ticket for this request because needs change code in many spaces. Our developers create it for you and it will be small custom mod.