Ticket #867 (closed Feature Request: fixed)

Opened 7 weeks ago

Last modified 6 weeks ago

Pagination: option to hide pagination info in url when linking back to first page

Reported by: neovive2 Owned by: Geert_DD
Priority: minor Milestone: 2.2.1
Component: Libraries Version: 2.2 Release
Keywords: pagination Cc:

Description

It would be nice to have a configuration option in the pagination library that hides the display of pagination variables in the url when linking back to the first page.

For example: in a blog, the first page "/blog/home" defaults to displaying the first five without any page info in the url, the next page "/blog/home/?page=2" or "/blog/home/page/2" displays the next five. When you click on the "previous" link, the url for the first page is now "/blog/home/?page=1" or "/blog/home/page/1". This extra url information is not necessary and could potentially be flagged as duplicate content by search engines.

Currently the only solution is to create a custom pagination view file and do multiple str_replace calls (or one nested str_replace) to modify the url for the first page:

	<?php if ($first_page): ?>
		<?php
			// a quick way to remove the page parameter on the first page - ?page=1 should not be displayed
			$url = str_replace('{page}', 1, $url); 
			$url = str_replace('?page=1', '', $url);
		 ?>
		<a href="<?php echo $url ?>">&lsaquo;&nbsp;<?php echo Kohana::lang('pagination.first') ?></a>				
	<?php endif ?>

It would be cleaner and easier to have the proper url sent directly by the Pagination library instead of having to add code to the view.

Change History

Changed 7 weeks ago by PugFish

  • owner changed from PugFish to Geert
  • status changed from new to assigned

Changed 6 weeks ago by Shadowhand

  • owner changed from Geert to Geert_DD

Changed 6 weeks ago by Geert

I'm open for suggestions on how to implement this. Some kind of URL generator helper function seems like the way to go in order to get rid of str_replace() and page=1 in the pagination views. However, that (static?) function will need access to multiple Pagination properties in order to work properly and creating Pagination::instance() is not an option if you want to continue to be able to have multiple Pagination objects on one page. Tricky.

Changed 6 weeks ago by Geert

Actually, passing the whole Pagination object to the view should do the trick. Working on it...

Changed 6 weeks ago by Geert

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r3570. Feedback appreciated.

Changed 6 weeks ago by neovive2

This looks really nice and much the views are much cleaner without all the str_replace calls.

Would it be more efficient to bind the pagination object to the view instead of using set?

Note: See TracTickets for help on using tickets.