0

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 Answers1

1

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.

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40
  • Thanks Hardik, that actually worked. But of course once I got this page working, I discovered that I didn't really want to output the categories like this anyway, as many of my posts will have multiple categories so they will show up multiple times if I do a master category index page. I ended up just using the default plugin method of clicking on a blog post category takes you to the output of all the posts with that category, instead of some kind convoluted master category index page. That's a long way of saying that your suggestion helped me figure out what I needed. Thanks! – matt.bryant Jun 18 '18 at 21:39
  • Yes, I was also about to suggest you that but I thought maybe you have some other idea :) anyways I am glad it helped you :) – Hardik Satasiya Jun 19 '18 at 06:34