Jump to content
jds43

Pagination with Url Segments

Recommended Posts

Hello,

I'm trying to paginate results that may have Url Segments and I want to modify the Base Url. How do I accomplish this within renderPager? I found docs here: https://processwire.com/api/ref/markup-pager-nav/render/, but it hasn't pointed me in the right direction. 

$pager->setBaseUrl(string $url);

    echo "<div id='pagination' class='uk-container uk-container-medium uk-margin-large-top'>";
        	echo $matches->renderPager(array(
    		    'nextItemLabel' => "Next",
    			'previousItemLabel' => "Prev",
                'currrentItemClass' => "uk-active",								    
    		    'listMarkup' => "<ul class='row uk-flex-right'>{out}</ul>",
    		    'itemMarkup' => "<li class='{class}'>{out}</li>",
    		    'linkMarkup' => "<a href='{url}' class='uk-button uk-background-secondary'><span class=''>{out}</span></a>",
    		));
    echo "</div>";

Or, does anyone know of a better option?

Share this post


Link to post
Share on other sites

Thanks @Ivan Gretsky

So, how would I set that value when I keep getting /events/page2 instead of /events/page2/?publish_until=2020-12-31 when I select the next paginated page for date filtered results?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ngrmm
      i have a event-page with a table.
      first column in this table is page-reference-field
      how can i find out if a urlSegment matches one of the rows having the same page-reference-field (page-id)?
      // all guests $allguests = new pageArray(); foreach($page->event_guests_table as $event_guests_table_row) { $allguests->prepend($event_table_row->guest); } // echo allguests would output: 1101|1102|1103|… // domain.tld/event/1101/ // show content if guest is in the table or redirect if($input->urlSegment1 ~= $allguests ) { // show content } else { // redirect }  
      which selector operator do i have to use? the one above does not work
    • By MilenKo
      Hello guys. I am super happy to be passing to the final cleanup of my first custom build theme and to start applying the SEO optimization modules/code. I noticed something strange this morning and can't find out where exactly is my issue. Hopefully it is a quick fix or silly miss on my side.
      So here is the issue: I am generating a list of all my recipes in the db using the following query:
      <?php if($page->numChildren) { //Build a selector and limit page results to 10 $recipe_results = $page->children("limit=4"); //Assign results of the array to $listing foreach($recipe_results as $index => $listing) { //Limit the text content to 160 chars using the function in function.php $text = $sanitizer->textarea(truncate("$listing->recipe_intro_text", 160)); ?> Then follows the boring part of html insert of the variables, clases etc. The listing works fine. So as far as there would be more than the planned results per page, I implemented the page rendering using the following code:
      <!-- Pagination --> <?php echo $recipe_results->renderPager(array( //Show font awesome right hand icon for next page 'nextItemLabel' => __("<i class='fa fa-hand-o-right'></i>"), //Show font awesome left hand icon for previous page 'previousItemLabel' => __("<i class='fa fa-hand-o-left'></i>"), //Define the active class of current page 'currentItemClass' => "current", //Define the block markup code 'listMarkup' => "<ul class='page-nav'>{out}</ul>", //Define the item markup code and applying currentItemClass 'itemMarkup' => "<li class='{class}'>{out}</li>", //Generating the link appearance of all buttons 'linkMarkup' => "<a href='{url}'>{out}</a>", )); ?> <!-- Pagination --> And again, everything worked perfectly after I allowed page numbers. 
      So then I implemented a few similar queries in the sidebar of my website, listing content from other page parents/children. Here is one example:
      <?php $favorite_books = $pages->find("template=books-inner, sort=-random, limit=3"); foreach($favorite_books as $b) { if (count($b->book_images)) { $thumb = $b->book_images->first->size(70,60)->url; $desc = $b->book_images->first->description; } else { $thumb = $settings->small_thumb->url; $desc = "NoThumb"; } ?> <li> <div class="thumb"> <a href="<?php echo $b->url?>"> <img src="<?php echo $thumb?>" alt="<?php echo $desc?>"/> </a> </div> <div class="detail"> <a href="<?php echo $b->url?>"><?php echo $b->title?></a> </div> </li> <?php } ?>  
      It was all working fine, until I started browsing page 2, 3, etc. It appears for some reason, that the pageRendering is applied not only to $recipe_results, but also to all requests from the widgets. So on page 1, I get the proper number of recipes and proper number of results in the widgets (books in this example). If I browse to page two, I still see the proper recipes number and everything else, but the widgets show only 1 result (as far as I have imported 4 test posts only). On page 3, it shows notihing in the widgets, but recipes are OK again.
      As far as to render pages I am using $recipe_results and the pageRender is called for that variable, I am not sure why it is also applied to $favorite_books and other widgets. Any suggestions or ideas what is going on? I tried to change every variable on the page thinking that I might be having a call to the same one, but it is obvious in the example that they do not match...
    • By Ivan Gretsky
      Good day!
      Suddenly I stumbled upon pagination once again. Pagination itself works as expected, but renderPager() returns the same markup on every paginated page. So it is 1st page current on every /pageN/. What can cause this? Please help.
    • By Pete Jones
      I'm just looking at trying to modify the output of the renderPager function. Instead of <li> for the page numbers, we need a select menu. Is it possible to modify the HTML that is returned or will I need to write my own function?
      Historically I would have used some form of override (Joomla) or inheritance to achieve this. What is the best way to 'build' on the PW core rather than rewrite it?
      What we're looking to achieve is have a dropdown rather than the intermediary numbers e.g.
      1 ~ DROPDOWN ~ LASTPAGE
    • By Sanyaissues
      Hi, i'm working on a website with some articles and categories. The structure is something like this:
      Home
      +Articles
      --First Article
      --Second Article
      +Categories
      --Category1
      --Category2
      I'm using the categories page as a field to categorize the articles and create the sections of the general navigation (home / category1 / category2).
      Currently the URL for a section looks like example.com/categories/category1/ and i want something like: example.com/category1/
      Any Ideas? Thanks!
×
×
  • Create New...