Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Pagination revamp "/blog/page/2"

Go to End

2 Posts   1107 Views


Community Member, 16 Posts

15 July 2011 at 12:27pm

Edited: 15/07/2011 12:44pm

I rewrote the pagination in my local Blog module to take the form of "/blog/page/2" instead of "/blog/?start=10". This is extremely similar to how the "tag/whatever" works. The biggest problem is how the include file relies on DataObjectSet's NextLink and PevLink, which I didn't want to rewrite (and probably shouldn't because of where they might be used).

in BlogTree.php -> BlogTree_Controller
add 'page' to $allowed_actions
modify inside method BlogEntries()

		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;

to be
		if (isset($_GET['start'])) {
			$start = (int) $_GET['start'];
		} else {
			$start = (int) $this->SelectedPage();
			$start = $limit * ($start - 1);

Add these methods (preferably down by the SelectedTag()

	/** - Added 7/14/2011 by Jared Kipe
	 * Return the currently viewing page, default is 1
	 * @return int
	function SelectedPage() {
		return ($this->request->latestParam('Action') == 'page') ? max((int)$this->request->latestParam('ID'), 1) : 1; 
	function PreviousPage() {
		return $this->SelectedPage() - 1;
	function NextPage() {
		return $this->SelectedPage() + 1;
	// override for some parent's implementation of page that causes runtime error using the 'page' action
	function page() {
		return array();

This will take some modification to the include file.

<% if BlogEntries.MoreThanOnePage %>
	<div id="PageNumbers">
			<% if BlogEntries.NotFirstPage %>
				<a class="prev" href="{$Link}<% if PreviousPage != 1 %>page/$PreviousPage<% end_if %>" title="View the previous page">Prev</a>
			<% end_if %>
		    	<% control BlogEntries.PaginationSummary(4) %>
					<% if CurrentBool %>
						<span class="current">$PageNum</span>
					<% else %>
						<% if Link %>
							<a href="{$Top.Link}page/$PageNum" title="View page number $PageNum">$PageNum</a>
						<% else %>
						<% end_if %>
					<% end_if %>
				<% end_control %>
			<% if BlogEntries.NotLastPage %>
				<a class="next" href="{$Link}page/$NextPage" title="View the next page">Next</a>
			<% end_if %>
<% end_if %>

EDIT: After thinking about it, this could probably cause problems when using tags or date, if there are are so many of either to cause pagination. Probably wrap the file with a giant <% if SelectedTag %> or use two different includes based on SelectedTag. Allowing you to use the "old" file with ?start=10 instead.


Community Member, 16 Posts

16 July 2011 at 12:07pm

As anticipated, the new file does cause some problems if you are viewing a tag or date at the same time and there are so many as to include pagination.

In both and Layouts I conditionally included the original file based on the presence of SelectedTag() and SelectedDate()

Like so..

	<% if SelectedTag || SelectedDate %>
		<% include BlogPagination_orig %>
	<% else %>
		<% include BlogPagination %>
	<% end_if %>