Jump to content

Get Google Breadcrumb markup, get url title in breadcrumb.tpl, SEO tip


kNife77

Recommended Posts

Hello,

 

So, first of all, this solution is for prestashop 1.6.0.9 but can easily be addapted for 1.6.X.X.

If you want to have Google Breadcrumb markup here is what you need to do:

 

First:

 

Go to themeFolder/breadcrumb.tpl and paste this:

<!-- Breadcrumb -->

{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}
<div class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
<!--	<div class="container"  > -->
	<meta itemprop="name" content="{$meta_title|escape:'html':'UTF-8'}"/>
		<a class="home" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" title="{l s='Return to Home'}"><i class="icon-home"></i></a>
	{if isset($path) AND $path}
		<span  class="navigation-pipe"  {if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
		{if $path|strpos:'span' !== false}
			
			<span  class="navigation_page" >
			{$path|@replace:'<a ': '<span > <span >

      			<a '|@replace:'data-gg="">': '> 
      			<span >'|@replace:'</a>': '</span></a></span>'}</span> </span>
		{else}
		
			{$path}
			
		{/if}
	{/if}

</div>

Then go to public_html/override/classes/ and create Tools.php

We need to alter function getPath

In override Tools.php write this:

class Tools extends ToolsCore{
public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
	{
		if (!$context)
			$context = Context::getContext();
		$id_category = (int)$id_category;
		if ($id_category == 1)
			return '<span class="navigation_end">'.$path.'</span>';
		$pipe = Configuration::get('PS_NAVIGATION_PIPE');
		if (empty($pipe))
			$pipe = '>';
		$full_path = '';
		if ($category_type === 'products')
		{
			$interval = Category::getInterval($id_category);
			$id_root_category = $context->shop->getCategory();
			$interval_root = Category::getInterval($id_root_category);
			if ($interval)
			{
				$sql = 'SELECT c.id_category, cl.name, cl.link_rewrite, cl.meta_title
						FROM '._DB_PREFIX_.'category c
						LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')
						'.Shop::addSqlAssociation('category', 'c').'
						WHERE c.nleft <= '.$interval['nleft'].'
							AND c.nright >= '.$interval['nright'].'
							AND c.nleft >= '.$interval_root['nleft'].'
							AND c.nright <= '.$interval_root['nright'].'
							AND cl.id_lang = '.(int)$context->language->id.'
							AND c.active = 1
							AND c.level_depth > '.(int)$interval_root['level_depth'].'
						ORDER BY c.level_depth ASC';
				$categories = Db::getInstance()->executeS($sql);
				$n = 1;
				$n_categories = count($categories);
				foreach ($categories as $category)
				{
					$full_path .='<span itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem" >'. (($n < $n_categories || $link_on_the_item) ? '<a itemprop="url" href="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['meta_title'], ENT_NOQUOTES, 'UTF-8').'">' : '').'<span itemprop="name" style="display:none;">'.htmlentities($category['meta_title'], ENT_NOQUOTES, 'UTF-8').'</span>'.
					htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
					(($n < $n_categories || $link_on_the_item) ? '</a>' : '').
					(($n++ != $n_categories || !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '').'</span>';
				}
				return $full_path.$path;
			}
		}
		else if ($category_type === 'CMS')
		{
			$category = new CMSCategory($id_category, $context->language->id);
			if (!Validate::isLoadedObject($category))
				die(Tools::displayError());
			$category_link = $context->link->getCMSCategoryLink($category);
			if ($path != $category->name)
				$full_path .= '<a href="'.Tools::safeOutput($category_link).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
			else
				$full_path = ($link_on_the_item ? '<a href="'.Tools::safeOutput($category_link).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($link_on_the_item ? '</a>' : '');
			return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
		}
	}
}

You are all set ;)

  • Like 1
Link to comment
Share on other sites

UPDATE

 

breadcrumb.tpl should look like this:

<!-- Breadcrumb -->

{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}
<div class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
<!--	<div class="container"  > -->
	<meta itemprop="name" content="{$meta_title|escape:'html':'UTF-8'}"/>
		<a class="home" href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" title="{l s='Return to Home'}"><i class="icon-home"></i></a>
	{if isset($path) AND $path}
		<span  class="navigation-pipe"  {if isset($category) && isset($category->id_category) && $category->id_category == (int)Configuration::get('PS_ROOT_CATEGORY')} style="display:none;"{/if}>{$navigationPipe|escape:'html':'UTF-8'}</span>
		{if $path|strpos:'span' !== false}
			
			<span  class="navigation_page" >
			{$path|@replace:'<a ': '<span > <span >

      			<a itemprop="item" '|@replace:'data-gg="">': '> 
      			<span >'|@replace:'</a>': '</span></a></span>'}</span> </span>
		{else}
		
			{$path}
			
		{/if}
	{/if}

</div>
  • Like 1
Link to comment
Share on other sites

  • 3 years later...

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...