Forum
Question about categories
I have added a categories set (case-studies) and populated it with 3 categories
I have a 2 page list and detail (working fine), and have added a perch:categories id to the detail template which is in my content templates folder.
What I want to do is to separate the 3 categories on the list page so they output the content into 3 blocks - each corresponding to a category
here is the list
<div class="studylist"><a href="/case-studies-detail.php?s=<perch:content id="slug" type="slug" />"><perch:content id="logo" type="image" width="400" crop="true" bucket="Study Images" output="tag" />
</a></div>
<perch:categories id="studycat">
here is the detail
<div class="left">
<perch:categories id="studycat" label="Case Study Type" set="case-studies" required="true" display-as="checkboxes">
<perch:if exists="video">
<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; height: auto; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://player.vimeo.com/video/<perch:content id="video" type="text" label="Video ID" required="false" title="true" size="m" />' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
<perch:else />
<img src="<perch:content id="image" type="image" label="Case Study Image" bucket="Study Images" help="Use this to add an image when you do not have a Vimeo video ID - images need to be at least 800px wide - an ideal solution would be a screengrab, but you must optimise it for the web - try using this www.tinypng.com" />" alt="<perch:content id="title" />" />
</perch:if>
</div>
<div class="right">
<h1>Case Study - <perch:content id="title" type="text" label="Company Name" required="true" title="true" order="1" /></h1>
<h3><i class="icon-glyph-1"></i> Brief</h3>
<perch:content id="brief" type="textarea" label="Brief" textile="true" size="xs" editor="markitup" />
<h3><i class="icon-glyph-2"></i> Challenges</h3>
<perch:content id="challenges" type="textarea" label="Challenges" textile="true" size="xs" editor="markitup" />
<h3><i class="icon-glyph-3"></i> Plans</h3>
<perch:content id="plans" type="textarea" label="Plans" textile="true" size="xs" editor="markitup" />
<h3><i class="icon-glyph"></i> Outcome</h3>
<perch:content id="outcome" type="textarea" label="Outcome" textile="true" size="xs" editor="markitup" />
</div>
<perch:content id="slug" for="title" type="slug" suppress="true" />
<perch:content id="logo" type="image" label="Company Logo" width="400" crop="true" bucket="Study Images" suppress="true" />
for the list page I was using
<?php
perch_content_custom('Study', array(
'template' => 'study-list.html',
));
?>
Which outputs all the detail content as normal - reading the documentation, to select the category, I thought this would work
<?php
perch_content_custom('Study', array(
'template' => 'study-list.html',
'category' => perch_get('category-name'),
));
?>
but it seems to have no effect - so I'm missing something. As I understand it, the templates don't need to be situated in the category templates folder - is that right, but will that effect things if later I want to have only the current category list on the detail page? (I'm thinking the catSlug?)
Can you help please. ( you can see the list/detail here: https://voxmedia.co.uk/case-studies.php )
cheers
Ben
perch_get()
gets a value from the query string. Do you havecategory-name=something
on the query string?Ok. I'm a bit confused. I (wrongly) assumed that since
was returning the uncategorised list items, it would be more straightforward to filter out the items by specific category since it is included on the template (and because I can select my categories when I enter content).
In my head I was looking to hard code the categories into each of the three blocks so for example since I have three categories that would mean
Is that not possible?
Apologies if these seem like stupid questions, I have been looking at this for hours and watching the categories video over and over and my brain is fried.
cheers
Ben
You would only use perch_get('category-three') if you have a querystring parameter named category-three.
If you just want to hardcode the string 'category-three' then you would use.
Hi Rachel
Tried as suggested - it's still not working - I did a <perch:show all> on the page - the first block has
The other two are just listings as before
but the first still returns nothing - the categories appear to be working, at least from the perspective that they are selectable when I add content - savills are Internal, co-op is both External and Projects
the page is here : https://voxmedia.co.uk/case-studies.php
I appreciate the help, I am keen not to overstep the mark with regards to support - let me know if this is more than reasonable.
Cheers
Ben
You need to use a category path, not just the end category name.
So that would be something like
case-studies/internal
Ah... that's exactly what I needed - I'm guessing this perhaps isn't the most sophisticated bit of coding - I will revisit this at a later date and try to do something that utilises the categories more fully and without resorting to the hard coding route - for today though it does the job - thank you both for your time and patience - you do a great job.
Cheers
Ben