0
votes

I am customizing my Blog plugin and have partial overrides set up for the Post, Posts, and Categories components in my theme. Currently my custom items.htm partial that is called into the component's default.htm has the code shown in my snippet.

Screenshot of items.htm code for October CMS Blog Categories component

I'm trying to show a categories page that summarizes all of the blog post categories used in the blog, and under each category shown any post that uses that category will be listed with a linked post title. Right now with the above code, the categories are showing up as they should, but ALL of my current test blog posts are being listed under each category. Is there a way to filer/alter that code to show only the posts under each category that use that category? I'm also including a screen capture to illustrate the current output on the front end. Thanks for any advice.

1

1 Answers

1
votes

Yes you can list post for each category

use this snippet but make sure you add post page and its URL should look like this be /post/:slug [ here imp part is :slug ]

<ul class="cats">
{% for category in categories %}
    <li {% if category.slug == currentCategorySlug %}class="active"{% endif %}>
        <a href="{{ category.url }}">{{ category.name }}</a>
        <ul class="posts">
            {% for post in category.posts %}
                <li>
                    <a href="{{ post.setUrl('post', this.controller) }}">{{ post.title }}</a>
                </li>
            {% endfor %}
        </ul>
    </li>
{% endfor %}
</ul>

we need to set post URL explicitly as it depends on the page name. you can use any name you want but that page should exist in CMS. here we use blog so we have created page post with URL /post/:slug

if any doubts, please comment.