Jump to content

UrlSegments with Pagination is throwing blank page [SOLVED]


Martinus
 Share

Recommended Posts

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:

  1. If I sort and then try pagination the url looks like this and works just fine : website-name/products/old-new/page2/
  2. 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;
    } ?>

 

Link to comment
Share on other sites

@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>

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

  • Martinus changed the title to UrlSegments with Pagination is throwing blank page [SOLVED]

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...