Shhhh Posted February 8, 2012 Share Posted February 8, 2012 Hi guys, I am thinking about a different solution to the meta description/title duplicate issue for pagination (besides adding page number or order type in them), a solution that would be appreciated by Google (and others) too. The objective would be to add the recommended rel=next and rel=prev in the header of the pages. Issues I had in mind: - pagination is "calculated" later and link tag must be in the header (how to get the links for next and prev?) - first and last page of a set must not contain prev and next Could any of the experts in here provide some hints where to start off in this "quest"? It would be helpful for many people. Thanks Link to comment Share on other sites More sharing options...
hannubys Posted March 8, 2012 Share Posted March 8, 2012 Hi Did you find the way to achieve it please? thanks Link to comment Share on other sites More sharing options...
renamed_account_335778 Posted March 9, 2012 Share Posted March 9, 2012 It's not very hard. You must override the controllers. For example: /override/controllers/CategoryController.php class CategoryController extends CategoryControllerCore { public function displayHeader() { parent::displayHeader(); // CODE HERE // put the code here to pass vars via Smarty to the .tpl file $this->productSort(); } } Then, edit theme: header.tpl And put the code for pagination: Info from Google: http://googlewebmast...nd-relprev.html Link to comment Share on other sites More sharing options...
LDP Posted March 16, 2012 Share Posted March 16, 2012 Thank you for this hint, but after many tries i'm still stuck and i can't get the prev and next links... I used parts of FrontController pagination() function, but i never get the correct links are these steps correct ? or is there a simpliest way to do this ? ==> PHP 1. get the category id 2. get the count of products in this category 3. get the number of products displayed per page by the user 4. calculate the number of pages for this category 5. get the number of page displayed 6. assign in smarty ==> TPL 1. assign link without pagination in a var='requestPage' like in pagination.tpl 2. check if actual page is 1 or last 3. create link with {$link->goPage($requestPage, thank you in advance for your help ! Link to comment Share on other sites More sharing options...
Mr S Posted May 10, 2012 Share Posted May 10, 2012 I am tagging my links in the pagination.tpl with rel="next" and rel="prev" using {if} statements I know google doc says to use them in the <link> tag but its just not logical. see HTML <a> rel Attribute http://www.w3schools...s/att_a_rel.asp {section name=pagination start=$start loop=$stop+1 step=1} {if $p == ($smarty.section.pagination.index-1)} <li class="nocurrent"><a href="{$link->goPage($requestPage, $smarty.section.pagination.index)}" rel="next">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}</a></li> {elseif $p == $smarty.section.pagination.index} <li class="current"><span>{$p|escape:'htmlall':'UTF-8'}</span></li> {elseif $p == ($smarty.section.pagination.index+1)} <li class="nocurrent"><a href="{$link->goPage($requestPage, $smarty.section.pagination.index)}" rel="prev">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}</a></li> {else} <li class="nocurrent"><a href="{$link->goPage($requestPage, $smarty.section.pagination.index)}">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}</a></li> {/if} {/section} Link to comment Share on other sites More sharing options...
cehashu Posted March 18, 2013 Share Posted March 18, 2013 has any one found a solution for writing the tags in the head section? thank you 1 Link to comment Share on other sites More sharing options...
stain Posted July 5, 2013 Share Posted July 5, 2013 (edited) Hey Cehashu, I had the same issue. I tried something and this code helped me out. Just paste the following code into the header.tpl before the closing </head>: {if $start!=$stop} {if $p != 1} {assign var='p_previous' value=$p-1} <link rel="prev" href="/{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}/{$link->goPage($requestPage, $p_previous)}" /> {else} {/if} {if $pages_nb > 1 AND $p != $pages_nb} {assign var='p_next' value=$p+1} <link rel="next" href="/{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}/{$link->goPage($requestPage, $p_next)}" /> {else} {/if} {/if} Here's one example in my Shisha Shop. First page: http://www.shishabro...asserpfeifen_9/ Second Page: http://www.shishabro...rpfeifen_9/?p=2 Third Page: http://www.shishabro...pfeifen_9/?&p=3 Last Page: http://www.shishabro...pfeifen_9/?&p=7 If you are also looking for an "dynamic" canonical tag integration, just paste the following code before the </head>, too. I was searching it at the same time, so it might help you: {if $page_name == index} <link rel="canonical" href="{$base_dir}" /> {elseif $page_name == product} <link rel="canonical" href="{$request_uri}" /> {elseif $page_name == category} <link rel="canonical" href="{$request_uri}" /> {else} <link rel="canonical" href="/{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}/" /> {/if} I'm not an IT guy, so I'm not sure if this is totally correct, but it works for me. Greetz, stain Edited July 5, 2013 by stain (see edit history) 4 Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted August 6, 2013 Share Posted August 6, 2013 (edited) For adding google pagination links in header as meta tags simply add this code in yout themes header.tpl file... {assign var = 'p_req_uri' value = '?'|explode:$request_uri} {if $start != $pages_nb AND $p != 1} {assign var = 'p_previous' value = $p-1 } <link rel="prev" href="{$p_req_uri[0]}/{$link->goPage($requestPage, $p_previous)}" /> {/if} {if $pages_nb > 1 AND $p != $pages_nb} {assign var='p_next' value= $p+1 } <link rel="next" href="{$p_req_uri[0]}/{$link->goPage($requestPage, $p_next)}" /> {/if} And its working fine for me... Edited August 6, 2013 by divyeshp (see edit history) 2 Link to comment Share on other sites More sharing options...
Rhobur Posted August 27, 2013 Share Posted August 27, 2013 (edited) @divyeshp: where to add it, before or after the </head> tag? Must be before but I am asking twice because after setting this, no effect appears! Something else, I have inserted the code above between the {literal} tag, is it all right? Edit 2: doesn't work without the {literal} tag either!? PS 1.5.4.1 Edited August 27, 2013 by Rho_bur (see edit history) Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted August 27, 2013 Share Posted August 27, 2013 @divyeshp: where to add it, before or after the </head> tag? Must be before but I am asking twice because after setting this, no effect appears! Something else, I have inserted the code above between the {literal} tag, is it all right? Edit 2: doesn't work without the {literal} tag either!? PS 1.5.4.1 Hello Caprice, I have added it just before </head> and its working fine... If you have enabled caching and smarty optimization then disable cache and recompile template from back office and then check in for some category that has more products... 1 Link to comment Share on other sites More sharing options...
Rhobur Posted August 27, 2013 Share Posted August 27, 2013 I did all above to no result. But it seems I have another issue all of a sudden, after clearing the cache and compile folders. I have also added a meta language tag in header.tpl to see if it appears on page source but it doesn't. My tpl's do not compile anymore, I have checked and re checked all settings in Tools->Performance and all is OK. Probably that it is why your code does not function. It is very puzzling, I will contact the provider to see if they have an idea. Thanks for replying and support! Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted August 27, 2013 Share Posted August 27, 2013 I did all above to no result. But it seems I have another issue all of a sudden, after clearing the cache and compile folders. I have also added a meta language tag in header.tpl to see if it appears on page source but it doesn't. My tpl's do not compile anymore, I have checked and re checked all settings in Tools->Performance and all is OK. Probably that it is why your code does not function. It is very puzzling, I will contact the provider to see if they have an idea. Thanks for replying and support! Which version of presta you are using?? I have done this here.. Please Check this testing url: http://rst.alakmalak.net/shop/index.php?id_category=3&controller=category view source of page and find rel="next" , you will find link to the next page of that category.. Link to comment Share on other sites More sharing options...
Rhobur Posted August 27, 2013 Share Posted August 27, 2013 Using PS 1.5.4.1 Yes, I see that it works to your link. But at my shop, for ex, http://www.caprice-shop.ro/29-gerstner or at any other category, it doesn't. And I can't find the string rel="next" despite adding your code into the header.tpl No compiled files in cache/smarty/compile either. It must be something with my hosting because I see no other explanation, all Tools->Preferences option are set as required but once I have deleted manually the content of compile no other files appeared. I'll look into this matter further but have no idea other than checking with the provider. Thanks for your time! Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted August 27, 2013 Share Posted August 27, 2013 (edited) Using PS 1.5.4.1 Yes, I see that it works to your link. But at my shop, for ex, http://www.caprice-shop.ro/29-gerstner or at any other category, it doesn't. And I can't find the string rel="next" despite adding your code into the header.tpl No compiled files in cache/smarty/compile either. It must be something with my hosting because I see no other explanation, all Tools->Preferences option are set as required but once I have deleted manually the content of compile no other files appeared. I'll look into this matter further but have no idea other than checking with the provider. Thanks for your time! Hello again, Can you please replace {assign var = 'p_req_uri' value = '?'|explode:$request_uri} to {assign var = 'p_req_uri' value = '?'|explode:{$smarty.server.REQUEST_URI[spam-filter] in code that i have given and check again if it works... Edited August 27, 2013 by divyeshp (see edit history) Link to comment Share on other sites More sharing options...
Rhobur Posted August 27, 2013 Share Posted August 27, 2013 No, it doesn't but I am getting pretty sure that this is not your code fault. To me it looks like anything I write in header.tpl is not reflected on the website. This is very weird because the code is in header.tpl and I have no compiled files at all, checked that on FTP. All cache, website or browser is deleted. I will contact the provider to see if there is something on their logs, on mine's there is nothing. Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted August 27, 2013 Share Posted August 27, 2013 No, it doesn't but I am getting pretty sure that this is not your code fault. To me it looks like anything I write in header.tpl is not reflected on the website. This is very weird because the code is in header.tpl and I have no compiled files at all, checked that on FTP. All cache, website or browser is deleted. I will contact the provider to see if there is something on their logs, on mine's there is nothing. Ok... When will you done with this let me know at least so i come to know that what is the problem in actual.. Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted September 11, 2013 Share Posted September 11, 2013 Hello Caprice, Have you solved problem with regards to Google pagination??? Link to comment Share on other sites More sharing options...
Rhobur Posted September 11, 2013 Share Posted September 11, 2013 Hello Caprice, Have you solved problem with regards to Google pagination??? Yes, just yesterday, you wouldn't believe what the issue was! I have previously opted for moving the site to another server of the same provider, to increase speed. But somehow they forgot to redirect the FTP access to the new location so all the files I have edited were the files in the old location with the files from the new location remaining the same. Of course the BO was pointing the the new location and that made the things confusing. Now, all is solved, I have added your code, it shows in the pages source; I have kept also the Prestashop pagination, is this OK? Can you check one of my categories for example, http://www.caprice-shop.ro/29-verighete-gerstner-clasic and tell me if it is allright? Thank you for your help! Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted September 11, 2013 Share Posted September 11, 2013 Yes, just yesterday, you wouldn't believe what the issue was! I have previously opted for moving the site to another server of the same provider, to increase speed. But somehow they forgot to redirect the FTP access to the new location so all the files I have edited were the files in the old location with the files from the new location remaining the same. Of course the BO was pointing the the new location and that made the things confusing. Now, all is solved, I have added your code, it shows in the pages source; I have kept also the Prestashop pagination, is this OK? Can you check one of my categories for example, http://www.caprice-shop.ro/29-verighete-gerstner-clasic and tell me if it is allright? Thank you for your help! Hello Caprice, Pagination is working fine in your site now... 1 Link to comment Share on other sites More sharing options...
Rhobur Posted September 11, 2013 Share Posted September 11, 2013 Thanks again for the help and the patience! All the best! Robert Link to comment Share on other sites More sharing options...
Divyesh Prajapati Posted September 11, 2013 Share Posted September 11, 2013 Thanks again for the help and the patience! All the best! Robert Welcome, Thats how we can help each other and improve prestashop!!!! Link to comment Share on other sites More sharing options...
FreshCommerce Posted March 5, 2014 Share Posted March 5, 2014 Hello! in our case we are using ajax pagination and PS 1.5.6. When you click "Next" or "Prev" the URL is like: http://www.domain.com/es/20-product-category#/page-2 Variable "$pages_nb" it´s OK with the total of pagination pages... but "$p" is always =1 so the code doesn´t work. Any idea of how to implement this in PS1.5 with friendly urls activated? Link to comment Share on other sites More sharing options...
jordiob Posted March 5, 2014 Share Posted March 5, 2014 I use the module "infinite scroll" Link to comment Share on other sites More sharing options...
Delart Posted April 4, 2014 Share Posted April 4, 2014 @divyeshp: your code is working great for me in pagination.tpl, but it is returning errors when placed in header.tpl: Undefined index: start in ... Trying to get property of non-object in... Undefined index: stop in ... Trying to get property of non-object in... Any hint what I am missing??? I'm at 1.4.11 Thanks! For adding google pagination links in header as meta tags simply add this code in yout themes header.tpl file... {assign var = 'p_req_uri' value = '?'|explode:$request_uri} {if $start != $pages_nb AND $p != 1} {assign var = 'p_previous' value = $p-1 } <link rel="prev" href="{$p_req_uri[0]}/{$link->goPage($requestPage, $p_previous)}" /> {/if} {if $pages_nb > 1 AND $p != $pages_nb} {assign var='p_next' value= $p+1 } <link rel="next" href="{$p_req_uri[0]}/{$link->goPage($requestPage, $p_next)}" /> {/if} And its working fine for me... Link to comment Share on other sites More sharing options...
Delart Posted April 11, 2014 Share Posted April 11, 2014 Well, it looks like this may be the problem: http://stackoverflow.com/questions/9565637/prestashop-variables-not-accessible-in-header-tpl-category-class-not-availabl So far I've been trying to override FrontController.php by adding the pagination variables to function displayHeader(), but I doesn't show any results (no errors though). Any help will be greatly appreciated! Link to comment Share on other sites More sharing options...
Delart Posted April 21, 2014 Share Posted April 21, 2014 @statictic I don't see the need for a canonical by default in page 2, 3, ... Perhaps it should only come up when sorting queries kick in (orderby, orderway, ...) ? By the way really looking forward to your module! Please make it compatible with 1.4.x This not match any seo improve. I develop a module to do this not only with paging, also with the rest of the pages. Minus "pagenotfound" page. For example this is placed in the head in category: <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=2'>http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=2" rel="canonical"> <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses" rel="prev"> <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=3" rel="next"> Or this for the index: <link href="http://localhost/presta6/es/" rel="canonical"> Problems come when is using nb_item per page, but I think the bots do not use this form. Also this form add this variable nb_item_per_page to the cookie. In prestashop 1.6.0.6 not updating correctly when changing this variable several times. Best regards Link to comment Share on other sites More sharing options...
laziali Posted January 27, 2015 Share Posted January 27, 2015 (edited) hello, i have similar problem with category pagination. i think i have set up rel=next/prev but in my webmaster tools meta desc are still duplicated, yet titles are not. anyone had the same problem? Edited: ok, i got my problem fixed - solution i found here in the forum. in my header.tpl file ive changed one row to {if isset($meta_description) AND $meta_description} <meta name="description" content="{$meta_description|escape:html:'UTF-8'}{if isset($smarty.get.p) && $smarty.get.p} ({$smarty.get.p}){/if}" />{/if} now my meta desc appear with page number at the end, just like my titles, so i guess its all ok now Edited January 28, 2015 by laziali (see edit history) 1 Link to comment Share on other sites More sharing options...
joseantgv Posted September 14, 2015 Share Posted September 14, 2015 This not match any seo improve. I develop a module to do this not only with paging, also with the rest of the pages. Minus "pagenotfound" page. For example this is placed in the head in category: <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=2'>http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=2" rel="canonical"> <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses" rel="prev"> <link href="http://localhost/presta6/es/8-dresses'>http://localhost/presta6/es/8-dresses?p=3" rel="next"> Or this for the index: <link href="http://localhost/presta6/es/" rel="canonical"> Problems come when is using nb_item per page, but I think the bots do not use this form. Also this form add this variable nb_item_per_page to the cookie. In prestashop 1.6.0.6 not updating correctly when changing this variable several times. Best regards Which is the module? Link to comment Share on other sites More sharing options...
joseantgv Posted September 14, 2015 Share Posted September 14, 2015 Hi joseantgv, you can see the module in action here: http://testopresto.altervista.org/es/3-mujer Saludos But can it be purchased or downloaded somewhere? Link to comment Share on other sites More sharing options...
Quentin Fahrner Posted June 25, 2021 Share Posted June 25, 2021 (edited) This is the way to go : Create a module (https://devdocs.prestashop.com/1.7/modules/creation/) Register to the "actionProductSearchAfter" hook (https://devdocs.prestashop.com/1.7/modules/concepts/hooks/) Copy/paste the following code into your module : /** * Implements the product search after action hook. */ public function hookActionProductSearchAfter($params) { if (!empty($count = $params['pagination']['pages_count'])) { if ($count > 1) { $current = $params['pagination']['current_page']; foreach ($params['pagination']['pages'] as $page) { if ($page['type'] === 'page') { $index = $page['page']; if ($index === ($current - 1)) { $this->context->smarty->assign([ 'HOOK_HEADER_LINK_PREV' => '<link rel="prev" href="'.$page['url'].'">', ]); } if ($index === ($current + 1)) { $this->context->smarty->assign([ 'HOOK_HEADER_LINK_NEXT' => '<link rel="next" href="'.$page['url'].'">', ]); } } } } } } NB: in the code above, the PHP Null Coalescing Operator (??) is only available starting with PHP 7 In your theme, modify the file "head.tpl" and the "head_seo" block to add the following code : {block name='head_seo'} ... {if isset($HOOK_HEADER_LINK_PREV)} {$HOOK_HEADER_LINK_PREV nofilter} {/if} {if isset($HOOK_HEADER_LINK_NEXT)} {$HOOK_HEADER_LINK_NEXT nofilter} {/if} {/block} Hope it helps ! Edited June 25, 2021 by Quentin Fahrner (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now