Forum

Thread tagged as: Problem, Error, Blog

Assign blog posts to categories

Hi,

I am trying to assign a blog post to a category that I have created. I can list the categories on my post.php page using:

<?php perch_categories(); ?>

Where my category template looks like this:

<perch:before><ul></perch:before>
    <li style="margin-left: <perch:category id="catDepth" type="hidden" />0px;">
        <a href="/blog/<perch:category id="catSlug" />">
            <h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4>
            <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
            <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" />
        </a>
    </li>
<perch:after></ul></perch:after>

My issue is that I cannot find a way through the backend/dashboard area to assign a post to a category.

I can filter my blog posts by category through the back-end in the blogs section, but nothing shows up in that category, as I am unable to assign a blog post one.

I also believe my <a> tag is incorrect as that takes me to a 404 page. I checked through the back-end, and the path is /blog/ followed by the page URL – which seems as if it is correct.

Thanks in advance for your help.

Darren Cusdin

Darren Cusdin 0 points

  • 4 years ago

James. In the posted template I don't see a <perch:categories ... > tagset around your <perch:category> tags. Maybe this is just an omission in your posted code. But you must surround your category tags with a categories tag set.

I did originally add <perch:categories> tags but that results in the categories not displaying.

Do you have the categories tag in your post.html template? Something like this:

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

This would enable you to assign posts to categories in the admin.