This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

skoobi
skoobi

Hi im having trouble filtering categories on my blog. I've made a custom template and with a custom category selector

{% for category in categories %}
    {% set postCount = category.post_count %}
    <li {% if category.slug == currentCategorySlug %}class="active"{% endif %}>
        <a href="{{ category.url }}">{{ category.name }}</a>

        {% if category.children %}
            <ul>
                {% partial __SELF__ ~ "::items"
                    categories=category.children
                    currentCategorySlug=currentCategorySlug
                %}
            </ul>
        {% endif %}
    </li>
{% endfor %}

But even though it goes to the correct page it wont fileter the categories. Ive set up the pages with the components and in the blog.htm page ive set:

Blog Page

Category List Component

Category Slug - :slug

Category page - blog-category-page

Post List Component

Category filter - :slug

Category page - blog-category-page

Post page - blog-single-page

Blog Category Page

Category List Component

Category Slug - :slug

Category page - blog-category-page

Post List Component

Category filter - :slug

Category page - blog-category-page

Post page - blog-single-page

Single post

Post List Component

Category filter - :slug

Category page - blog-category-page

Im not sure what the issue is. Ive tried it with the component and the partial but still wont work...

Blog page partial / Blog Category

{% set posts = blogPosts.posts %}

{% for post in posts %}
    <div class="{% for category in post.categories %} {{ category.slug }}  {% endfor %} card-row js-isotope-item">
        {% for image in post.featured_images %}
            <div class="card-row-img col-md-7 col-lg-8 hidden-sm hidden-xs" style="background-image:url({{ image.path }})"></div>
        {% endfor %}
        <div class="card-block col-md-offset-7 col-lg-offset-8">
            <div class="card-posted"><a href="#">{{ post.user.first_name }}</a> on {{ post.published_at|date('M d, Y') }}</div>
            <h4 class="card-title">{{ post.title }}</h4>
            <div class="card-text">{{ post.summary|raw }}</div>
            <a href="{{ post.url }}" class="card-read-more">Continue Reading...</a>
        </div>
    </div>
{% else %}
    <h4 class="card-title">{{ noPostsMessage }}</h4>
{% endfor %}

{% if posts.lastPage > 1 %}
    <ul class="pagination">
        {% if posts.currentPage > 1 %}
            <li><a href="{{ page.baseFileName|page({ (pageParam): (posts.currentPage-1) }) }}">&larr; Prev</a></li>
        {% endif %}

        {% for page in 1..posts.lastPage %}
            <li class="{{ posts.currentPage == page ? 'active' : null }}">
                <a href="{{ page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
            </li>
        {% endfor %}

        {% if posts.lastPage > posts.currentPage %}
            <li><a href="{{ page.baseFileName|page({ (pageParam): (posts.currentPage+1) }) }}">Next &rarr;</a></li>
        {% endif %}
    </ul>
{% endif %}

<div class="navbar-spacer hidden-sm hidden-xs"></div>

Blog post

{% set post = blogPosts.post %}

<article>

    {% for image in blogPost.post.featured_images %}

    <div class="post-thumbnail masked" style="background-image:url({{ image.path }})">

        {% endfor %}
        <div class="container">
            <div class="row">
                <div class="col-md-10 col-lg-6 col-md-offset-1 col-lg-offset-2">
                    <!-- <div class="title-info">{{post.title}}</div> -->
                    <h1 class="display-1">{{ blogPost.post.title}}</h1>
                </div>
            </div>
        </div>
    </div>

    <div class="page-content">
        <div class="primary">
            <div class="container">
                <article class="post">

                    <div class="row">
                        <div class="col-md-10 col-lg-8 col-md-offset-1 col-lg-offset-2">

                            <h2>{{ blogPost.post.title}}</h2>

                        </div>
                    </div>

                    <div class="entry-content">
                        <div class="row">
                            <div class="col-md-10 col-lg-8 col-md-offset-1 col-lg-offset-2">
                                {{ blogPost.post.content_html|raw }}
                            </div>

                        </div>

            <div class="entry-footer">
              <div class="row">
                <div class="col-md-10 col-lg-8 col-md-offset-1 col-lg-offset-2">
                <div class="posted-on">
                            <small>Posted by <a class="url fn n" href="#">{{ blogPost.post.user.first_name }}</a> on {{ blogPost.post.published_at|date('M d, Y') }}</small>
                            </div>
                  <div class="tags-links">
                    <span>Categories:</span>
                    {% for category in blogPost.post.categories %}
                        <a href="">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
                    {% endfor %}
                  </div>

            </div>
        </div>
    </div>
</article>

<div class="navbar-spacer hidden-sm hidden-xs"></div>

Last updated

melki59235
melki59235

Have you figured out yet ? For my october, as long you dont use space on your categories, it will be alright and it will filter out.

huyn0331477
huyn0331477

if you use rainlab.blog then

Category

public $belongsToMany = [
    'posts' => ['RainLab\Blog\Models\Post',
        'table' => 'rainlab_blog_posts_categories',
        'order' => 'published_at desc',
        'scope' => 'isPublished'
    ],
    'posts_count' => ['RainLab\Blog\Models\Post',
        'table' => 'rainlab_blog_posts_categories',
        'scope' => 'isPublished',
        'count' => true
    ]
];

it not defined "category.children" yet.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.