Forum

Thread tagged as: Question

perch_categories subcategory title?

Quesiton

How do I display a subcategory title?

perch_categories

The code below displays the catTitle for top level categories. It doesn't work for subcategories?

perch_categories([
    'set' => 'faqs',
    'template' => 'category--faq-desc.html',
    'filter' => 'catSlug',
    'match' => 'eq',
    'value' => perch_get('cat'),  
]);

Routes

debug shows me my route is matched

Matched route: faqs/[slug:cat]/[slug:subcat]

perch:showall

This table shows I'm viewing the balance subcategory, but the catTitle displays the parent category, Exercises. How do I display the subcategory title?

<perch:showall /> table for my template category--faq-desc.html

Perch Screenshot

Template: category--faq-desc.html

<perch:before>
<div>
</perch:before>
    <h1><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h1>
    <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
<perch:after>   
    </div>
</perch:after>
Stephen Meehan

Stephen Meehan 4 points

  • 3 years ago

I came up with a solution. Sometimes it helps to write out the problem.

if (perch_get('cat') && perch_get('subcat')) {
            perch_categories([
            'set' => 'faqs',
            'template' => 'category--faq-desc.html',
            'filter' => 'catSlug',
            'match' => 'eq',
            'value' => perch_get('subcat'),  
            ]);

    } 
    elseif (perch_get('cat')) {
            perch_categories([
            'set' => 'faqs',
            'template' => 'category--faq-desc.html',
            'filter' => 'catSlug',
            'match' => 'eq',
            'value' => perch_get('cat'),  
            ]);
    }