carlos Posted January 12, 2012 Share Posted January 12, 2012 Hello All, so after finding most of my information from scouring the forums. I was able to build a page that sorts it's children based on their category. This works out great. For this particular use case, I also need to page through each individual child, by use a next and prev button. The catch to this, is that I also want the url to updated. the url should read: http://site.dev/ad-p...ategory/product But instead it reads: http://site.dev/ad-p.../category/page2 when I add pagination to the mix. So I'm pretty stuck now and I'm not sure how to proceed. Also the way I went about using categories, if there is a simpler solution or best practice, please let me know. I would like to improve as much as I can. Thanks and here is the code I'm using below: <nav> <ul> <?php $name = $sanitizer->pageName($input->urlSegment1); $prodName = $sanitizer->pageName($input->urlSegment2); $bodyContent = $pages->get("/ad-products/$prodName"); // get all categories $categories = $pages->get("/categories/")->children; $products = $pages->get("/ad-products/"); // loop categories foreach($categories as $cat) { //class is on if on the page($cat) or the child(what's the parent) $class = $name == $cat->name ? " class='on'" : ''; echo "<li $class><a href='{$products->url}{$cat->name}/'>{$cat->title}</a></li>"; } ?> </ul> </nav> <div id="content"> <?php // output pagination links $prod = $page->children("limit=2, sort=-date"); $pagination = $prod->renderPager(); echo $pagination; echo "<p>$bodyContent->body</p>" //3rd Nav echo "<nav id='sec-nav'>". "<ul>". "<li><em>Skip To:</em></li>"; foreach($categories as $cat) { $prodName = $sanitizer->pageName($input->urlSegment2); // find all samples having the current category $products = $pages->get("/ad-products/")->find("categories=$cat"); if( $name == $cat->name ) { foreach($products as $child) { $class = $prodName == $child->name ? " class='on'" : ''; echo "<li $class><a href='{$child->name}'>{$child->title}</a></li>"; } } } echo "</ul>". "</nav>"; ?> </div><!-- /content --> Link to comment Share on other sites More sharing options...
ryan Posted January 12, 2012 Share Posted January 12, 2012 Since you are wanting to do next/prev with single products, I don't think you'll want to use PW's pagination at all. I think this also makes sense given that you want the URL to reflect the product name rather than a page number. So if I'm understand your example correctly, I think you'll want to do something like this: <?php $cat = the current category page; $product = the current product page; $products = $pages->find("parent=/ad-products/, categories=$cat"); $prev = $product->prev($products); $next = $product->next($products); if($prev->id) echo "<a href='./{$prev->name}'>Previous: {$prev->title}</a> "; if($next->id) echo "<a href='./{$next->name}'>Next: {$next->title}</a>"; Link to comment Share on other sites More sharing options...
carlos Posted January 12, 2012 Author Share Posted January 12, 2012 Thank you sir!!! That worked a charm!!! I'm amazed at the simplicity of it. Link to comment Share on other sites More sharing options...
Pete Posted January 12, 2012 Share Posted January 12, 2012 Thank you sir!!! That worked a charm!!! I'm amazed at the simplicity of it. I know what you mean - many times I've looked for a complicated solution where a simpler one would do in ProcessWire. 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