Jump to content

Recommended Posts

I have a site structure as follows

-- Shirt One
-- Shirt Two
-- Shoe One
-- Shoe Two

-- Spring Summer
-- Fall Winter

Each page has a 'category' page field.

I'm trying create a navigation that shows only the child categories as follows:

-- Spring Summer
-- Fall Winter
-- Spring Summer 
-- Fall Winter

When Shirts -> Spring Summer is clicked i'd see only spring summer shirts. Same for Shoes, you'd only see Spring summer items for shoes.

Help please.


Share this post

Link to post
Share on other sites

You can use URL segments for the category name. Or a GET variable - the principle is the same but the URL segments are nicer. Look for the URL segment in your template and then use it in a selector for your product pages.

If you read through Ryan's URL segments tutorial you should get the gist of it.

Make your navigation links by iterating over the category options, or if you want to get fancy, just the categories that are used by products in that section.

Share this post

Link to post
Share on other sites
1 hour ago, Robin S said:

You can use URL segments for the category name. Or a GET variable - the principle is the same but the URL segments are nicer. Look for the URL segment in your template and then use it in a selector for your product pages.

Thanks for the quick response. The first paragraph in your answer threw me off a little. Would i have to activate URL segments on the Category Template OR the Category Child Template? Otherwise would URL segments have to be enabled in the product templates instead?  Thank you.

Here's and example of what i'm hoping to achieve. http://www.etro.com/en_wr/ 'Man' and 'Woman' under collections both have the same categories i.e. 'Autumn Winter 16-17' although they list different items for 'Man' and 'Woman'F / .W 2016 -17

Share this post

Link to post
Share on other sites

You would enable URL segments on the template used for "Shirts" and "Shoes". You would allow segments that match the names of your category pages and throw a 404 for anything else.

For example:

if($input->urlSegment1) {
    $category_names = $pages->find('template=category')->explode('name');
    if(in_array($input->urlSegment1, $category_names)) {
        // build your selector to filter the products using $input->urlSegment1
    } else {
        throw new Wire404Exception();
} else {
    // show all the products


  • Like 2

Share this post

Link to post
Share on other sites

Robin S,

Thanks for the response.Stepped away from the project for a bit and i'm now back to it. I'll try the implementation and provide feedback. 

Thanks again.

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 jds43
      Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages.
      Things to Do (would only display three, six, seven, nine in select)
      -thing one (-category three, -category nine)
      -thing two (-category six, -category seven)

      Lodging (would only display one, two, three, four in select)
      -lodging one (-category one, -category two)
      -lodging two (-category three, -category four)

      Dining (would only display five, six, seven, eight in select)
      -dining one (-category five, -category six)
      -dining two (-category seven, -category eight)
      Categories(hidden page)
      -category one
      -category two
      -category there
      -category four
      -category five
      -category six
      -category seven
      -category eight
      -category nine
      -category ten
      $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this.
    • By stanoliver
      Good morning everyone!
      I have a growing number of posts about cars, bikes, airplanes, etc. 
      The following code (below) just works fine and returns only the posts of the category=cars as I desired together with pagination.
      In my url I have for example /categories/cars/car1 or /categories/bikes/bike1
      I do want to filter my posts not only with ... category=cars ... but also with category=bikes or category=airplanes and at best:
      If my url is /categories/bikes/ then ... category=cars ... should be overwritten or replaced by ... category=bikes ... 
      If my url is /categories/airplanes/ ... then the filter should be ... category=airplanes ... (I know a work around by creating almost identical templates where I could just change the "category=cars" part of my code but that's comes of a prize by repeating a lot of identical code and is not a good habit). In the documentation I read something about the "has_parent" selector but I could not get to work it related to the urls mentioned above.
      <?php foreach ( $results = $pages->find('id>1, template=templateblogpost, category=cars, limit=5, sort=-postdate') as $post 😞?> <!-- Blog entry --> <div class="g8-card-4 g8-margin g8-white"> <!--<img src="/g8images/bridge.jpg" alt="Norway" style="width:100%">--> <div class="g8-container"> <h3><b><?= $post->title; ?></b></h3> <h5>Datum: <span class="g8-opacity"><?= $post->postdate; ?></span></h5> </div>   <div class="g8-container"> <p><?= $post->posteditor; ?></p> <div class="g8-row"> <div class="g8-col m8 s12"> <p> <a href="<?= $post->url; ?>"><button class="g8-button g8-padding-large g8-white g8-border"><b>Details lesen &raquo;</b></button></a> </p> </div> <div class="g8-col m4 g8-hide-small"> <!--<p><span class="g8-padding-large g8-right"><b>Comments &nbsp;</b> <span class="g8-badge">2</span></span></p>--> </div> </div> </div> </div> <!-- END BLOG ENTRIES --> <?php endforeach; ?>   <? echo $results->renderPager(array( 'nextItemLabel' => "rückwärts", 'previousItemLabel' => "vorwärts")); ?>
    • By adrian_gp
      Hello everyone,
      I'm new in this forum and my english is not perfect so sorry for the mistakes.
      I have an Blog Project and i will use categories. 
      Here is the structure:
      Blog -> displays all the Blogposts (template=BlogPage) Post-Name -> display the specific Post (template=BlogPost) Categories -> not visible in the menu (template=CategoriesPage) Categorie-Name -> not visible in the menu (template=CategoriePage) For your information:
      (BlogPost) every blogpost has its own page (BlogPost) in Admin i can select the categorie per Field -> SelectMultiple Pages (Checkbox) (fieldname=categories) (Blog) displays all the BlogPosts and all the categories under the ParentTemplate CategoriesPage, which also have their own side Now the Problem:
      On Blog -> I would like to click on a category and only see the post that has this category checked in the BlogPost.
      CategoriePage -> what do I have to insert there to show only the specific posts which use the checked categorie?

      Let me know if you need more information

      Thanks for your support
    • By zaib
      I've a page "blog" which have child pages (blog posts). Right now I've 11 pages (blog posts) and I'm fetching all the posts in my "blog" pages which displaying fine, Issue is only 10 results are showing this is how I'm fetching
      $entries = $pages->find("template=blog-entry"); foreach($entries as $entry){ <a href='{$entry->url}'>$entry->title</a> }  
    • By DarkwaveSurfer
      I'm total newbie for php and Processwire so be patient with me
      I'm trying to make a simple blog. 
      BLOG - list of all posts   (template: blog-list)
      -- Post no.1   (template: blog-entry)
      -- Post no.2   (template: blog-entry)
      -- Post no.3   (template: blog-entry)
      CATEGORIES   (template: categories)
      --  Jobs   (template: category)
      -- Technology   (template: category)

      Template for post "blog-entry" has Page field set to Multiple pages and input as Checkboxes. So it is posible to select CATEGORIES children pages via checkbox when editing blog post.
      This is how I show selected categories within blog-entry template for current blog post:
      foreach ($page->categories as $category) { echo "<a href='{$category->url}'>{$category->title}</a>"; } How do I show selected categories within blog-list template?
      I need list of all posts with their Title, body and selected categories from Page field checkbox. I managed to show title and body but not categories.
      This is my code so far:
      <?php echo "<h1>" . $page->get('headline|title') . "</h1>"; $entries = $pages->find('template=blog-entry')->sort('-created'); foreach($entries as $entry) { echo "<a href='{$entry->url}'>"; echo $entry->categories->title; //not working echo "<h2>{$entry->title}</h2>"; echo $entry->body; echo "</a>"; }; ?> Also how do I show on Jobs page (template: category) list of all posts that have jobs category selected?

  • Create New...