Welcome Guest, Not a member yet? Register   Sign In
Pagination first link with suffix
#1

[eluser]Angilo[/eluser]
Hi,

the first link in pagination is not giving the right URL when you are using suffix.
For SEO purpose you want a link of this type:
"/products/overview/30/Watches/Men"

products = controller
overview = function
30 = pagination
Watches = filter on the page
Men = filter on the page

But since it is a filter, it's not always used. When you do use the filter, and you are not on the first page, the URL to the first page is wrong. The url will be
"/products/overview"

What you want is
"/products/overview/0/Watches/Men"

Why? Because else the users' filter will reset.

What to change?
Remove line 199 in system/libraries/pagination.php

Line 199:
Code:
$first_url = ($this->first_url == '') ? $this->base_url : $this->first_url;

Add this to line 195:
Code:
$first_url = $this->base_url.$this->prefix.(0 * $this->per_page).$this->suffix;

This will fix it. It will also fix the URL when you click at "1" or "<".
#2

[eluser]Jeroen van Meerendonk[/eluser]
Hi there,

Thanks for the tip, that's what I was looking for. But that didn't worked until I made a change:

Instead:
Code:
$first_url = $this->base_url.$this->prefix.(0 * $this->per_page).$this->suffix;

I added "$this->":
Code:
$this->first_url = $this->base_url.$this->prefix.(0 * $this->per_page).$this->suffix;

I haven't fully tested it but with this change seems to work.
#3

[eluser]InsiteFX[/eluser]
I hope you are extending the Pagination Library and not modifying it!
#4

[eluser]Unknown[/eluser]
[quote author="Jeroen van Meerendonk" date="1333968097"]Hi there,

Thanks for the tip, that's what I was looking for. But that didn't worked until I made a change:

Instead:
Code:
$first_url = $this->base_url.$this->prefix.(0 * $this->per_page).$this->suffix;

I added "$this->":
Code:
$this->first_url = $this->base_url.$this->prefix.(0 * $this->per_page).$this->suffix;

I haven't fully tested it but with this change seems to work.[/quote]

I also changed
Code:
$first_url to $this->first_url

on line 200, that makes the "first page" link works
#5

[eluser]Unknown[/eluser]
Hey, you can have the first page include GET params without hacking by using the first_url config setting.

Code:
$config['first_url'] = $config['base_url'].$config['suffix'];

Example:
Code:
$config['base_url'] = 'http://mysite.com/controller/index';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config['first_url'] = $config['base_url'].$config['suffix'];
$this->pagination->initialize($config);

I don't know if there's any documentation on this. I found it by looking through source code.




Theme © iAndrew 2016 - Forum software by © MyBB