Forum

Thread tagged as: Blog

Changes to blog/categories

I’ve just updated a site to use the new categories and blog version, but I’m having a slight issue. I’m adding classes to each blog post in the list and colouring them depending on the category. I previously got the category in post_in_list.html using:

<perch:blog id="categories" encode="false" />

But that doesn’t seem to work anymore, it previously returned the slug (as far as I can remember) but now it returns a number (which I assume is the id of the category).

I’ve tried various alternatives, but none work.

What do I need to change it to to work with the latest version?

Nick Bramwell

Nick Bramwell 5 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you followed the update instructions?

https://docs.grabaperch.com/addons/blog/installation/

Hello Drew,

yes I’ve followed the instructions which made the categories show when editing a blog post and shows the categories in the post itself, but the post_in_list.html template doesn’t work.

I’ve tried various things like:

<article class="hentry <perch:category id="catSlug" type="slug" />">

But I think I’m missing something obvious somewhere.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to use the <perch:categories> tags from your post.html template.

Here is my post.html template:

<article class="hentry">
    <perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" suppress="true" />
    <h2 class="published">Published <perch:blog id="postDateTime" type="date" label="Date" time="true" format="%d %B %Y" divider-before="Meta information" /></h2>
    <img src="<perch:blog id="image" type="image" width="320" height="320" crop="true" label="Image" order="4" />" alt="<perch:blog id="postTitle" />" />
    <div class="description entry-content">
    <perch:blog id="postDescHTML" type="textarea" label="Post" order="2" editor="markitup" textile="true" size="xxl autowidth" required="true" />
  </div>
</article>

<perch:blog id="excerpt" type="textarea" label="Excerpt" textile="true" order="3" size="s" editor="markitup" suppress="true" />
<perch:blog id="image" type="image" width="500" height="500" suppress="true" />

<perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes">
 <a href="archive.php?cat=<perch:category id="catSlug" type="slug" suppress="true" />">
    <perch:category id="catTitle" type="text" suppress="true" />
 </a>
</perch:categories>

and here is my post_in_list.html template:

<article class="hentry <perch:category id="catSlug" />">
    <header>
        <h2>
            <a href="<perch:blog id="postURL" type="hidden" />" rel="bookmark" class="entry-title">
        <perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" />
      </a>
    </h2>
        <p class="published">published <perch:blog id="postDateTime" type="date" label="Date" time="true" format="%d %B %Y" divider-before="Meta information" /> </p>
    </header>
    <img src="<perch:blog id="image" type="image" width="320" height="320" crop="true" label="Image" order="4" />" alt="<perch:blog id="postTitle" />" />
    <div class="description entry-content">
    <perch:blog id="excerpt" textile="true" />
  </div>
</article>
<perch:after>
    <perch:if exists="paging">
        <div class="paging">
            Page <perch:blog id="current_page" /> of <perch:blog id="number_of_pages" />
            <perch:if exists="not_first_page">
                <a href="<perch:blog id="prev_url" encode="false" />">Previous</a>
            </perch:if>
            <perch:if exists="not_last_page">
                <a href="<perch:blog id="next_url" encode="false" />">Next</a>
            </perch:if>
        </div>
    </perch:if>
</perch:after>

If I take out suppress from the post.html template it shows the category with a link including the slug, but it doesn’t output the slug in post_in_list.html

Drew McLellan

Drew McLellan 2638 points
Perch Support

So, in your list template, add your categories.

<perch:categories id="categories" set="blog">
 <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />">
    <perch:category id="catTitle" type="text" />
 </a>
</perch:categories>

Thanks Drew,

it works perfectly now. I hadn’t realised it needed <perch:categories> everyone I wanted to use them, I thought it was just when setting categories, it does make sense now I think about it though.

Thanks again for all the help.