Forum

Thread tagged as: Question, Problem, Configuration

categories slug

Hello

I have a list set of categories displaying nicely in a list https://epicweekends.co.uk/category.php

But I am unsure how to define my category item slug so when you click on a category list item/link it goes to more detail on that item.

Thanks, Denise

My page is...

 <?php perch_categories(array(
                        'set'=> 'destinations',
                        'template' => 'cat-list.html',

                    )); 
    perch_blog_categories(array(
        'template' => 'category_single.html',
        'filter' => 'visible',
        'match' => 'eq',
        'value' => '1',
    ));
?>                   

My category-list template....

<perch:before>
<ul class="piclist">
</perch:before>
<li class="piclist">  <div class="col-sm-3">
  <a class="brighten" href="destinations/<perch:category id="catSlug" type="slug" for="catTitle" label="Slug" />" >         
                    <img class="img-responsive picsml" src="<perch:category type="image" id="destimage" height="167px" crop="true" />" alt="<perch:category type="text" id="destination" />" />

            <div id="listitle"> <blockquote><h6 class="listing"><perch:category id="destinations/<perch:category id="catSlug" type="slug" for="catTitle" label="Slug" />" type="text" />
</h6></blockquote></div></a>
</div>

            </li>
<perch:after>
</ul>
</perch:after>

My category item template (category-single.html)...

    <img class="img-responsive pic" src="<perch:category type="image" id="destimage" label="Destination image" crop="true" order="2" />" alt="<perch:category id="catTitle" type="smarttext" label="Title" required="true" title="true" order="1"  />" />
                <div id="credit"><perch:if exists="link"><a class="credit" href="https://<perch:category id="link" type="url" label="Image credit link (optional)" order="4"  divider-after="Highlights"/>"></perch:if><perch:else><perch:if exists="credit">Image | <perch:category type="text" id="credit" label="Image credit" order="3" /></perch:if></a></div>

                 <div class="headlineq"><h2 class="detail"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h2></div>
              <ul class="highlights">
                    <perch:if exists="highlight1">

<li class="bullet">
<span class="highighttxt"><perch:category id="highlight1" type="text" label="Activity Overview | 1st highlight" order="5" />
</span></li></perch:if>
<perch:if exists="highlight2"><li class="bullet">
<span class="highighttxt"><perch:category id="highlight2" type="text" label="2nd highlight" order="6" /></span>
</li></perch:if>
<perch:if exists="highlight3"><li class="bullet">
<span class="highighttxt"><perch:category id="highlight3" type="text" label="3rd highlight" order="7" /></span>
</li></perch:if>
   </ul>
         <div class="moreinfo">
<perch:category id="blurb" type="textarea" label="More Activity Info" html="true" editor="redactor" order="11"/>
  </div>


<perch:before><ul></perch:before>
<li style="margin-left: <perch:category id="catDepth" type="hidden" />0px;">
    <h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4>
    <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />

</li>
<perch:after></ul></perch:after>  
Denise Courtney

Denise Courtney 0 points

  • 6 years ago
Simon Clay

Simon Clay 127 points

Hi Denise,

perch:category tags need to be within perch:categories tags. So, for example your category-list template would start and end with perch:categories tags. Something like this:

<perch:categories id="destinations" label="Type of work" set="destinations" required="true">

  <!-- your category list template here -->

</perch:categories>

Does that help?

Hi Simon

Thanks for your reply but when this is added to my category-list template I get none of my set items listed at all.

I added it also to my master category template category-single.html and then had options to add 'types of work" i.e. categories from my destinations set but this is not required and I want to show all anyway. Just need the slug to work.

At the moment for example the category bath goes to epicweekends.co.uk/destinations/bath (no page exists) but I guess it should still contain category.php?

Simon Clay

Simon Clay 127 points

Hi Denise, You should find it works if you change the url in your cat-list.html to:

<a class="brighten" href="destinations.php?s=<perch:category id="catSlug" type="slug" for="catTitle" label="Slug" />" >

Ok I'll give that a go, thanks. Do I still need to include

<perch:categories id="destinations" label="Type of work" set="destinations" required="true">

<!-- your category list template here -->

</perch:categories>

in both templates ?

Simon Clay

Simon Clay 127 points

I thought you did need those on the listing template, but perhaps not.

Let me know if that works.

Hello again Simon

Yes that worked thanks and clicks through fine to page but cannot get just the one category item listed with reference to the slug. They all appear again with the different template.

On my destinations.php page I have at the moment... ~~ <?php
if (perch_get('cat')) { perch_category(perch_get('cat'),array( 'template'=>'category_single.html'

));
perch_categories('Destinations', array(
  'template' => 'cat_list.html',
  'page'=>'/category.php',
  'category' => perch_get('cat'),
  'match' => 'eq',
  'count' => 1,

));
} else {
  perch_categories();
}
?>

~~

Any ideas where Im going wrong, thank you

A little update...

I have one item listed correctly but it does not match the url slug.

ie. When I click on one of the list of categories it just always leads to the first item.

My destinations.php is now

~~

<?php perch_categories(array(

        'category'   => perch_get('s'),
        'template'   =>'category-single.html',
        'match' => 'catslug',
'count' => 1,

    )); ?>

~~

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the intended purpose of

 'match' => 'catslug',

?

The match option is for use with filter and value and contains the type of comparison to perform (eq, gt, lt and so on).

Oh ok, I don't need that then. How do I get the correct category info then?

For example the url at the top of my page gives the correct output but the page does not.

My category.php

<?php perch_categories(array( 'set'=> 'destinations', 'template' => 'cat-list.html', 'category' => perch_get('cat'),

                )); 


?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to provide a full category path, not just a category slug.

set-slug/category-slug

I tried that in my template but it makes no difference

<a class="brighten" href="destinations.php?s=destinations/<perch:category id="catSlug" type="slug" for="catTitle" label="Slug" />" >

It's the same set, just need to view categories within it.

Thanks for your patience Im sure I missing sth obvious here!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You're trying to list the categories in a set?

perch_categories([
    'set' => 'destinations',
]);

Yes, which I have and when you select a category from the list it takes you to this individual category with more info etc.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So like this?

 /category.php?set=destinations
perch_categories([
    'set' => perch_get('set'),
]);

That made no difference I'm afraid. The set is working fine and displays all categories, it is the pasty to the category where the error is. I am only working with one set here with a list of categories within.

if I give you the url will that help you see the error

https://www.epicweekends.co.uk/category.php

if you click on anything but the first item you will see the issue.

Thank you for your time and quick responses, its very appreciated!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, this looks like you don't want to list categories.

Is the problem the destinations.php page?

Yes, and the fact that it is not grabbing the category selection.

It has to work like list/detail but I need to use categories as I am using this as a filter elsewhere. The category.php is a bit of a testing page as the moment.

So I want to list categories in the set destinations on category.php and then single categories on destinations.php.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the code you're using and describe what you want to output?

Ok yes, I have simplified slightly to just show essential items.

my list template (simplified slightly) for my set page (category.php) is

<perch:before>
<ul >
</perch:before>
<li>  <div>

<a href="destinations.php?s=<perch:category id="catSlug" type="slug" for="catTitle" label="Slug" />" >

                    <img src="<perch:category type="image" id="destimage" height="167px" crop="true" />" alt="<perch:category type="text" id="destination" />" />

            <div> <blockquote><h6><perch:category id="catTitle" type="smarttext" label="Title" required="true" />
</h6></blockquote></div></a>
<div>
 </li>
<perch:after>
</ul>
</perch:after>

AND my single category (master) template for destinations.php is...

<div>
<img src="<perch:category type="image" id="destimage" label="Destination image" crop="true" order="2" />" alt="<perch:category id="catTitle" type="smartest" label="Title" required="true" title="true" order="1"  />" />
</div>

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

            <a href="#" class="btn-u btn-u-large" style="margin-left:5px">+ ENQUIRE</a>

            </div>             

  <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
  <perch:categories id="setTitle" type="smarttext" label="Title"  suppress="true" />
<perch:categories id="setSlug" type="slug" for="setTitle" label="Slug"  suppress="true" />

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is your problem with the templates or with the data you're pulling back (or failing to)?