Martinus Posted September 29, 2022 Posted September 29, 2022 I have my 'browse' template where I include one file for display. On my template I use urlsegments (only 1) for sorting, then the include file is called. Everything works fine for it. Yesterday I implemented pagination and it is working fine. On my browse template I have Allow on page numbers and url segments. But here comes my bug: If I sort and then try pagination the url looks like this and works just fine : website-name/products/old-new/page2/ But when I sort again after pagination, it looks like this and throws me a blank page : website-name/products/old-new/name-asc/ How can I correct this? The switch for sorting looks like this: if(strlen($input->urlSegment2)) throw new Wire404Exception(); switch($input->urlSegment1) { case '': // Segment 1 is empty so default sort: NEW-TO-OLD $order = "-date"; $sorted = "newest first"; break; case 'old-new': // DATE $order = "id"; $sorted = "oldest first"; break; default: // Anything else? Throw a 404 throw new Wire404Exception(); } The switch for including a file looks like this: <?php switch($page->name) { case "sellers": case "brands": case "categories": case "departments": // If this page is a Parent-page named 'sellers, vendors, categories or departments'. $items = $pages->find("parent={$page->name}, sort=$order"); $file = "_grid-view-parents.php"; break; case "products": // If this page is a Parent-page named 'products'. $items = $pages->find("parent=/products/, sort=$order, limit=4"); $file = "_grid-view-products.php"; break; } ?>
markus-th Posted September 29, 2022 Posted September 29, 2022 How look the output? I think the generated sortinglink ist wrong.
markus-th Posted September 29, 2022 Posted September 29, 2022 43 minutes ago, Martinus said: Hi, what do you mean by output? I mean the template that generates the HTML of the sortinglink.
Martinus Posted September 29, 2022 Author Posted September 29, 2022 @Markus Thomas In the included file nothing fancy: <?php namespace ProcessWire; ?> <div class="row m-0"> <div class="d-flex justify-content-center align-items-center"> <?php echo $items->renderPager([ 'page' => wire('page'), 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'listMarkup' => '<nav aria-label="navigation"><ul class="pagination">{out}</ul></nav>', 'itemMarkup' => '<li class="page-item {class}">{out}</li>', 'linkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentLinkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentItemClass' => "active" ]); ?> </div> </div> <div class="row m-0"> <?php foreach($items as $item) { ?> <div class="col-md-3"> <div class="card g-0 border rounded mb-3"> <div class="p-1"> <img class="img-fluid" src="<?php echo $item->image->url ;?>"></img> </div> </div> </div> <?php } ?> </div>
markus-th Posted September 29, 2022 Posted September 29, 2022 That is okay, and i use it always like this. 1 hour ago, Martinus said: But when I sort again after pagination, it looks like this and throws me a blank page : website-name/products/old-new/name-asc/ But your sorting-HTML is not in this template ... this is only the pagination.
Martinus Posted September 29, 2022 Author Posted September 29, 2022 My sorting is in the header. <form method="get"> <!-- // sort options --> <div class="dropdown-center me-2"> <button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Sort <?php echo $page->title;?> </button> <ul class="dropdown-menu small"> <li><a class="dropdown-item" href="name-asc">Name (A-Z)</a></li> <li><a class="dropdown-item" href="name-desc">Name (Z-A)</a></li> <li><a class="dropdown-item" href="old-new">Oldest first</a></li> <li><a class="dropdown-item" href="new-old">Newest first</a></li> </div> </form>
markus-th Posted September 29, 2022 Posted September 29, 2022 10 minutes ago, Martinus said: <li><a class="dropdown-item" href="name-asc">Name (A-Z)</a></li> This link simply adds "name-asc" to the end of the actual URL. But you have to switch between "name-asc", "name-desc" etc. For this you have to specify the complete url https://processwire.com/api/ref/page/url/
Martinus Posted September 29, 2022 Author Posted September 29, 2022 At this link is says how to take care of the urlsegmentstr which is what I did using the switch. https://processwire.com/docs/front-end/how-to-use-url-segments/ The form dropdown button passes exactly what is in the switch in order to do the sort option. Or am I missing something?
markus-th Posted September 29, 2022 Posted September 29, 2022 Just try <li><a class="dropdown-item" href="<?= $page->url('name-asc') ?>">Name (A-Z)</a></li> instead of <li><a class="dropdown-item" href="name-asc">Name (A-Z)</a></li> This should fix the link
Martinus Posted September 29, 2022 Author Posted September 29, 2022 @Markus Thomas Thanks! I now have this, which seems to work: <li><a class="dropdown-item" href="<?php echo $page->url;?>name-asc">Name (A-Z)</a></li> It now is forcing the sort options as an urlsegment after the normal url, and the pagination always at the end.
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