Lance O. Posted June 3, 2013 Share Posted June 3, 2013 I'm working on a simple blog that requires date-based archives and I'm having a difficult time wrapping my head around pagination with urlSegments. I've modified Marty's code from this post: http://processwire.com/talk/topic/1356-news-section-archives/?p=12313 My modified code: $thisyear = date("Y"); $year = (int) $input->urlSegment1; $blog = $pages->find( "parent=/blog/, template=post, limit=2, sort=-date, date>=$year-01-01, date<=$year-12-31" ); foreach ( $blog as $blogitem ) { $str = "{$blogitem->date}"; $publishyear = strtotime( $str ); $urlyear = date( "Y", $publishyear ); echo "<h2><a href='{$blogitem->url}'>{$blogitem->title}<span class='date'>{$blogitem->date}</span></a></h2>"; echo "<p class='summary'>{$blogitem->summary}</p>"; } My code for pagination: $pagination = $blog->renderPager(array( 'numPageLinks' => '10', // Default: 10 'getVars' => '', // Default: empty 'baseUrl' => '', // Default: empty 'listMarkup' => "{out}", 'itemMarkup' => "{out}", 'linkMarkup' => "<a href=\"{url}\">{out}</a>", 'nextItemLabel' => 'Next', 'previousItemLabel' => 'Previous', 'separatorItemLabel' => '', 'separatorItemClass' => '', 'nextItemClass' => '', 'previousItemClass' => '', 'lastItemClass' => '', 'currentItemClass' => 'current' )); echo '<div id="posts-nav">' . $pagination . '</div>'; My blog structure looks like this: http://domain.com/blog/archive/2010/11/ And should look like this when paginated: http://domain.com/blog/archive/2010/11/page2/ But instead looks like this: http://domain.com/blog/archive/page2 The year and month segments aren't being written into the pagination links. I've read the documentation on pagination and scoured the forum for an example of how to get this to work, but I haven't had any luck and am at a loss at this point. I'd really appreciate it if someone could point me in the proper direction. Link to comment Share on other sites More sharing options...
kkoala Posted June 5, 2013 Share Posted June 5, 2013 Try removing baseUrl from your renderPager options array. If you set it to an empty string, as you currently have, it will ignore your URL segments. The documentation says the default is "blank", which could lead one to believe it means an empty string or null. I quickly peeked under the hood of the module, and it seems the default is not really empty/blank; rather, it seems to detect the full current page URL including segements, so you can just omit it completely in the options. 5 Link to comment Share on other sites More sharing options...
Lance O. Posted June 5, 2013 Author Share Posted June 5, 2013 Thank you, kkoala! That tiny little modification did the trick. I'd rub your fuzzy little belly if I could! Hopefully the documentation can be updated so no one else has to experience the same issue. Link to comment Share on other sites More sharing options...
diogo Posted September 11, 2013 Share Posted September 11, 2013 For those working with pagination and several urlSegments. This seems to be pretty bulletproof: $currentUrl = $page->url.$input->urlSegmentsStr."/"; $pagination = $results->renderPager(array('baseUrl' => $currentUrl)); 4 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 11, 2013 Share Posted September 11, 2013 impressive first post kkoala ! Welcome ! Link to comment Share on other sites More sharing options...
diogo Posted September 11, 2013 Share Posted September 11, 2013 Martijn, you are 3 months late 2 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 11, 2013 Share Posted September 11, 2013 Then it's even more impressive. Thought I had read all the topics & posts 1 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