Forum

Thread tagged as: Blog

Blog subcategories path

Hello all,

I followed Rachel's Blog video guide and I managed to reproduce the result. I tried to populate my Blog setup with subcategories:

This is my markup:

<ul>
    <li>
        <a href="#">Item Level 1</a>
        <ul>
            <li>
                <a class="cur" href="#">Sub item Level 2</a>
                <ul>
                    <li><a href="#">Sub item Level 3</a></li>
                    <li><a href="#">Sub item Level 2</a></li>
                    <li><a href="#">Sub item Level 2</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Sub item Level 2</a>
                <ul>
                    <li><a href="#">Sub item Level 2</a></li>
                    <li><a href="#">Sub item Level 2</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

When I add the subcategories in perch CMS at "Listing categories in ‘Blog’ set" I get the correct visual tree representation and the correct path e.g:

blog/item-level-1/
blog/item-level-1/sub-item-level-2/
blog/item-level-1/sub-item-level-2/sub-item-level-3

etc.

I use the template: perch/templates/blog/category_link.html as Rachel does in the video guide.

<perch:before>
<h3 class="[ u-h6 u-text-align--right ]">Categories</h3>
<hr>
<ul>
</perch:before>
    <li>
        <a href="archive.php?cat=<perch:category id="catSlug" />"><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a>
    </li>
<perch:after></ul></perch:after>
<perch:before>

and this is what is being produced:

<ul>
    <li><a href="archive.php?cat=item-level-1">Item Level 1 (1)</a></li>
    <li><a href="archive.php?cat=sub-item-level-2">Sub item Level 2 (1)</a></li>
    <li><a href="archive.php?cat=sub-item-level-3">Sub item Level 3 (1)</a></li>
</ul>

What do I need to do to have this one produced?

<ul>
    <li>
        <a href="#">Item Level 1</a>
        <ul>
            <li>
                <a class="cur" href="#">Sub item Level 2</a>
                <ul>
                    <li>
                        <a href="#">Sub item Level 3</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

I must tell you that my experience with perch CMS is extremely limited

Thank you in advance

Konstantinos Antoniadis

Konstantinos Antoniadis 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you mean in terms of customising the HTML, or setting the right options to get the level of navigation?

I was referring to the HTML. How can I restrict the subcategories to only be shown under the proper categories?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can test for catDepth in the template and display different markup.

If you add <perch:showall /> to your template, you should be able to see all the variables that are available for you to display and test against.

Hello again,

this is what I have figured out:

<perch:before>
<h3>Categories</h3>
<ul>
</perch:before>
    <perch:if id="catDepth" value="1">
        <li>
            <a href="<perch:category id="catPath" />"><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a>
        </li>
    </perch:if>
<perch:after></ul></perch:after>

This will only display the 1st-level categories.

So if lets say we wanted to create something like this:

|Animals
|____Mammals
|________Bear
|________Dog
|____Birds
|________Bald eagle
|____Reptiles
|________Snake
|________Lizzard

this code would only render the category Animals

If I wanted to output the first AND the second level categories what should I do?

<perch:before>
<h3>Categories</h3>
<ul>
</perch:before>
    <perch:if id="catDepth" value="1">
        <li>
            <a href="<perch:category id="catPath" />"><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a>
            <ul>
                <perch:if id="catDepth" value="2">
                <li>
                    <a href="<perch:category id="catPath" />"><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a>
                </li>
                </perch:if>
            </ul>
        </li>
    </perch:if>
<perch:after></ul></perch:after>

The above does not work. Any idea why?

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you say it doesn't work - what output do you get?