Jump to content

Category link title -> meta description


Recommended Posts

Hi,

 

The title (alt) in my category tree links are now showing the category description (which is quite long). I want to show the meta description instead.

 

I (guess I) know which files I have to edit:

modules/blockcategories/blockcategories.php

public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
{
 global $link;
 $children = array();
 if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
  foreach ($resultParents[$id_category] as $subcat)
   $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
 if (!isset($resultIds[$id_category]))
  return false;
 return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
  'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
  'children' => $children);
}

 

 

modules/blockcategories/category-tree-branch.tpl

<a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>

 

I kinda understand the code, however I lack the skill of adding new features. Can someone help to let the function getTree also return the category's meta description?

 

Thanks!

Link to comment
Share on other sites

  • 11 months later...
  • 5 months later...
  • 4 years later...

OK, in blockcategories.php you need to change:

if (isset($resultIds[$id_category]))
		{
			$link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);
			$name = $resultIds[$id_category]['name'];
			$desc = $resultIds[$id_category]['description'];
		}
else
		$link = $name = $desc = '';
 
		$return = array(
			'id' => $id_category,
			'link' => $link,
			'name' => $name,
			'desc'=> $desc,
			'children' => $children 
		);
		return $return;

to

if (isset($resultIds[$id_category]))
		{
			$link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);
			$name = $resultIds[$id_category]['name'];
			$desc = $resultIds[$id_category]['description'];
			$meta = ("" == $resultIds[$id_category]['meta_title']) ? $resultIds[$id_category]['name'] : $resultIds[$id_category]['meta_title'];
		}
else
	$link = $name = $desc = $meta = '';
 
	$return = array(
		'id' => $id_category,
		'link' => $link,
		'name' => $name,
		'desc'=> $desc,
		'children' => $children, 
		'meta' => $meta  
	);
	return $return;

then

SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite

to

SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite, cl.meta_title

and finaly in category-tree-branch.tpl from

<a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|truncate:255:'...'|escape:'html':'UTF-8'}">
		{$node.name|escape:'html':'UTF-8'} </a>

to

<a href="{$node.link|escape:'html':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}
		title="{$node.meta|escape:'html':'UTF-8'}">{$node.name|escape:'html':'UTF-8'}</a>

More details in Polish are available here on my blog. Best Regards!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...