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

tekjava
tekjava

I created a new partial replacing the default markup for the category page. However it is listing all posts no matter the category.

Code from category page using :slug and :page:

<div class="row">
    <div class="col-sm-8">
        {% partial 'post-list.htm' %}
    </div>
    <div class="col-sm-4">
        {% partial 'post-categories.htm' %}
   </div>
</div>

Generate list of categories for side bar:

{% set categories = blogCategories.categories %}
{% set currentCategorySlug = blogCategories.currentCategorySlug %}

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

Generate list of posts:

{% set posts = blogPosts.posts %}
<ul class="list-group">
    {% for post in posts %}
        <li class="list-group-item">
            <h3><a href="{{ post.url }}">{{ post.title }}</a></h3>

            <p class="info">
                Posted
                {% if post.categories.count %} in {% endif %}
                {% for category in post.categories %}
                    <a href="{{ category.url }}">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
                {% endfor %}
                on {{ post.published_at|date('M d, Y') }}
            </p>
{% if post.featured_images.count %}
    <div class="featured-images text-left">
        {% for image in post.featured_images %}
            <p><a href="{{ post.url }}">
                <img
                    data-src="{{ image.filename }}"
                    src="{{ image.path }}"
                    alt="{{ image.description }}"
                    style="max-width: 25%" /></a>
            </p>
        {% endfor %}
    </div>
{% endif %}
            <p class="excerpt">{{ post.summary }}</p>
        </li>
    {% else %}
        <li class="no-data">{{ noPostsMessage }}</li>
    {% endfor %}
</ul>

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

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

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

What could be incorrect about the above?

Last updated

tekjava
tekjava

Solved by switching the

:page
&
:slug
parameter to external in for "post-list"

1-2 of 2

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