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

kevin.vermeulen
kevin.vermeulen

Hi all,

I want to have my blog pages as follow:

  • Books (category)
    -- Fiction (subcategory)
    --- Blogposts (posts)
    -- Non-Fiction (subcategory)
    --- Blogposts (posts)
  • Movies (category)
    -- Action (subcategory)
    --- Blogposts (posts)

In Books and Movies, I want to show only the connected subcategories of the category. There's the "categoryList" available but that one will show all categories as a list. I want to have similar as you can do in a post to get the categories

{% for category in post.categories|sort %}
 {% if category.parent %}
   <a href="/{{ category.parent.slug }}/{{ category.slug }}">{{ category.name }}</a>
 {% else %}
  <a href="/{{ category.slug }}">{{ category.name }}</a>
 {% endif %}
{% endfor %}

Anyone an idea on this matter?

Last updated

kevin.vermeulen
kevin.vermeulen

Found a solution.
It could be coding way better for sure but at least it's working:

  1. https://www.kvntravel.nl/nl
  2. https://www.kvntravel.nl/nl/europa
  3. https://www.kvntravel.nl/nl/europa/kroatie
  4. https://www.kvntravel.nl/nl/europa/kroatie/roadtrip-kroatie-met-camper
{% for category in categories %}
    {% for child in category.children if category.name|lower in this.page.title|lower %}
        <article class="col-md-6 child-{{ child.id }}">

            <div class="blogpost my-1 my-sm-2 pl-0 ml-0 my-md-3">
                {% if child.featured_images.count %}{% for image in child.featured_images|slice(0,1) %}   
                    <img src="{{ image.path|resize(540, 208, { mode: 'crop', extension: 'jpeg'}) }}">
                {% endfor %}{% endif %}
                <a href="/{{activeLocale}}/{{ child.parent.slug }}/{{ child.slug }}" title="{{ child.name }}">
                    <h3 class="pt-1">
                        {{ child.name }}
                        {% for catCount in child.posts_count %}({{ catCount.count }}){% endfor %}
                    </h3>
                    <p class="summary">{{ child.description }}</p>
                </a>
            </div>
        </article>

    {% endfor %}
{% endfor %}
info63609
info63609

Solution:

=
function onStart() {
// Get the actual category
$slug = $this->param('slug');
// Get the childs categories
$this['childs'] = RainLab\Blog\Models\Category::whereHas('parent', function ($query) use 
($slug) { $query->where('slug',$slug); })->get(); }
 =

and

<aside>
<h2 class="aside-title">{{ category.name }}</h2>
<div class="aside-body">
    {% for child in childs %}
    <article class="col-md-12 ">
        <div class="blogpost ">
            <a href="{{ child.slug }}" title="{{ child.name }}">
                <h6>
                    {{ child.name }}
                    {% for catCount in child.posts_count %}({{ catCount.count }}){% endfor %}
                </h6>
                <p class="summary">{{ child.description }}</p>
            </a>
        </div>
    </article>
    {% else %}

    <p>Empty</p>

    {% endfor %}
</div>
</aside>

1-3 of 3

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