Forum

Thread tagged as: Question, Problem

Display categories as individual sets

I'm having some confusion over how to display categories correctly. Have read all of the documentation and forum posts but nothing seems to quite explain it. I am trying to output my categories as a list except I want one set as the main list and two other sets within dropdown menus. I have everything working correctly to output all categories from all sets in a list but I can't work out how to separate them and select just the 'service' set for example.

I am using set="set name here(work or service)" within my categories template but it doesn't seem to make a difference.

This is my category template:

<perch:before>
  <div class="filter layout">
    <ul class="inline-list">
    <li>Filter:</li>
    <li><a href="/films-work">All</a></li>
</perch:before>
      <li>
        <a href="/films-work-category/<perch:category id="catPath" />">
          <perch:category id="catTitle" type="smarttext" set="work" label="Title" required="true" />
        </a>
      </li>
<perch:after>
    <li class="dropdown-tgl">
      <a href="#" onclick="return false;">Service</a><i class="icon-keyboard_arrow_down" aria-label="Scroll down to see more"></i>
      <ul class="dropdown">
        <li>
          <a href="#">
            <perch:category id="catTitle" type="smarttext" set="service" label="Title" required="true" />
          </a>
        </li>
      </ul>
    </li>
    </ul>
  </div><!--/filter-->
</perch:after>

This is my .php page:

<div class="block--films block--films--work__list">
  <?php
    perch_categories(array(
      'template' => 'films_work-filter.html',
    ));
    perch_content_create('Work Examples', array(
          'template'   => 'films_work-detail.html',
          'multiple'    => true,
          'edit-mode' => 'listdetail',
    ));
    perch_content_custom('Work Examples', array(
      'template'=>'films_work-listing.html'
    ));

  ?>
</div><!--/block-films-->

Any advice would be much appreciated!

Rob Saunders

Rob Saunders 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Use the set option.

https://docs.grabaperch.com/functions/categories/perch-categories/

perch_categories([
    'set' => 'my-set',
]);

Ah ok so you have to keep the markup outside of the template. Got it thank you.

.php page:

  <div class="filter layout">
    <ul class="inline-list">
      <li>Filter:</li>
      <li><a href="/films-work">All</a></li>
      <?php
        perch_categories(array(
          'template' => 'films_work-filter.html',
          'set' => 'work',
        ));
      ?>
      <li class="dropdown-tgl">Service<i class="icon-keyboard_arrow_down" aria-label="Click to see more"></i>
        <ul class="dropdown">
          <?php
            perch_categories(array(
              'template' => 'films_work-filter-service.html',
              'set' => 'service',
            ));
          ?>
        </ul>
      </li>
      <li class="dropdown-tgl">Sector<i class="icon-keyboard_arrow_down" aria-label="Click to see more"></i>
        <ul class="dropdown">
          <?php
            perch_categories(array(
              'template' => 'films_work-filter-sector.html',
              'set' => 'sector',
            ));
          ?>
        </ul>
      </li>
    </ul>
  </div><!--/filter-->

Work Filter template:

<li>
  <a href="/films-work-category/<perch:category id="catPath" />">
    <perch:category id="catTitle" />
  </a>
</li>

.htaccess:

 RewriteRule ^films-work-category/([a-zA-Z0-9-/]+)$ films-work-category.php?cat=$1 [L]