Jurist Posted May 5, 2017 Share Posted May 5, 2017 Hello, I am trying to write a simple module that adds link rel=prev, next and canonical before </head> closing but I've encountered a problem with $p variable, which I found after using {debug} function. It says that $p value is always 1, no matter on which page of category I am, no matter if this is first main category or page nr 3 it always return value of 1. This stops me from checking the $p value condition. I've found that layered Layered navigation block v2.2.0 changes the address from: mydomain.com/id-category-name?p=2 to mydomain.com/id-category-name#/page-2 which caused the problem. When I manually enter mydomain.com/id-category-name?p=2 it says that $p = 2 correctly. When clicked on number 2 on the product page as usual (mydomain.com/id-category-name#/page-2) it says $p = 1 always. I would really appreciate possible solution with this, as it caused duplicate content issue and prevents our store from getting to the top positions of the search results. Link to comment Share on other sites More sharing options...
Jurist Posted May 8, 2017 Author Share Posted May 8, 2017 (edited) I've found temporary resolution to fix $p variable, at the moment I just removed url rewriting from mydomain.com/themes/my-theme/js/modules/blocklayered/blocklayered.js: /*if (typeof(current_friendly_url) === 'undefined') current_friendly_url = '#'; $('div.pagination a').not(':hidden').each(function () { if ($(this).attr('href').search(/(\?|&)p=/) == -1) var page = 1; else var page = parseInt($(this).attr('href').replace(/^.*(\?|&)p=(\d+).*$/, '$2')); var location = window.location.href.replace(/#.*$/, ''); $(this).attr('href', location + current_friendly_url.replace(/\/page-(\d+)/, '') + '/page-' + page); }); */ and now category has proper url and $p domain, there's one more problem: how to get variable of last page of the category? If there are 100 products spread across 10 category pages, how to check if page is the last one? EDIT: Ok, I think I've managed to sort it out, JS changes the URL and $p variable only for user, not for google. Therefore $p variable can be safely used. With Javascript execution blocked, $p variable returned proper value depending on active site. Solution from this topic works well: https://www.prestashop.com/forums/topic/154705-pagination-with-link-rel-meta-tags/ Edited May 9, 2017 by Jurist (see edit history) Link to comment Share on other sites More sharing options...
javgoji Posted July 16, 2017 Share Posted July 16, 2017 Same occurs with category pagination. $p variable always has 1 value. Prestashop 1.6.1.15 Link to comment Share on other sites More sharing options...
Yankee_PL Posted May 6, 2018 Share Posted May 6, 2018 Hi. Did you sorted it out? I tried also solution mentioned by Jurist, but no luck with dynamic pagination.. Presta 1.6.1.18 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