Forum

Thread tagged as: Question, Problem, Shop

Shop Listing Page - Using Category Title in H1

Hi, been scratching my head for a few hours now about how I can display the current Category Title within a h1 on my listing.php page which displays a grid of products in that category.

Currently got as far as this - but it displays all the categories, how can I just pull out the current one?

<h1>
    <span>
    <?php perch_categories([ 
        'category' => 'products/'.perch_get('category'),
        'category' => 'products/'.perch_get('s'),
        'filter'=>'catTitle',
        'template'=>'title.html']
    ); ?>
    </span>
</h1>

The contents of the title.html file is simply

<perch:category id="catTitle" type="smarttext" label="Title" required="true" />

Elsewhere on the same page I am displaying the products in this category with the following:

<?php perch_shop_products([ 
        'category' => 'products/'.perch_get('category'), 
        'category' => 'products/'.perch_get('s'),
        'template' => 'products/list.html'
        ]); ?>

Thanks in advance, I realise this is probably a simple thing to do!

Nik

Running Perch 2.8.34 PHP 7.0.16 MySQL 5.5.54

Nik Gill

Nik Gill 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Use perch_category() to display a single category. perch_categories() displays a listing.

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

Thanks Drew, sorted it. Cheers for the point in the right direction.