PontusHorn/Pico-Tags

Removing links to tag pages from the blog list

Closed this issue · 10 comments

For either of the below two snippets in the blog posts list page, the links to tag pages appear as blog posts. Ideally, links to tag pages shouldn't appear in the blog list page as blog posts because they aren't blog posts.

Code from Pico-Tags doc,

{% for page in pages if page.title %}
    <article>
        <h2><a href="{{ page.url }}">{{ page.title }}</a></h2>
        <p>{{ page.description }}</p>
    </article>
{% endfor %} 

Code that I use in my blog list page,

<article>
        {% for page in pages|sort_by("time")|reverse %}
        {% if page.id starts with "blog/" and not page.hidden %}
        <div class="post">
            <h3 class="list"><a href="{{ page.url }}">{{ page.title }}</a></h3>
            <p class="date"><a href="{{ base_url }}/blog/tags/{{ page.meta.tags|lower }}">{{ page.meta.tags }}</a></p>
        </div>
        {% endif %}
        {% endfor %}
</article>

How do I remove them from the blog list page?

Based on what you wrote in your other issue, you could probably remove them by changing the filter from:

{% if page.id starts with "blog/" and not page.hidden %}

To:

{% if page.id starts with "blog/" and not page.id starts with "blog/tags/" and not page.hidden %}

Let me know if that works!

I had tried a variation of this earlier, but it never worked. I now tried the exact same code and it's a miss.

In both cases, I got a blank page. I mean a page with header and footer, but the content is blank. No posts matching that condition.

I was able to replicate the issue. It seems the problem is the order of execution in Twig's conditional syntax. Try this:

{% if (page.id starts with "blog/") and not (page.id starts with "blog/tags/") and not page.hidden %}

That worked for me.

This time, the blogs list, but it doesn't eliminate the tag pages. The result is pretty much the same as it was with the original code posted in the OP.

Would it help if you see the code of the entire page?

Yeah, that might help. What I posted above works fine on a test site I have locally, so I'm not sure where we're differing at the moment.

Extremely sorry. I've been trying that code snippet on the tag theme rather than the blog theme. I have tried your code now on the blog list theme and it works. The tag pages aren't shown. Thanks a lot for your help by the way, for both issues.

So my next task is to create a sidebar that displays all the tags. I am sure the same filtering can be used: to only display pages with starting with /blog/tags/ in that section.

No worries 🙂

As mentioned earlier, I am now trying to display the tag cloud on the side bar in both the blog list page and the tag pages. My content directory is as follows:

content/blog/tags/ - where the all tag pages are present which follows tags.twig theme
content/blog/ - where the blog posts are present
content/blog.md - where the blog posts are listed which follows blog.twig theme

blog.twig has the sidebar as follows,

<section id="tag_cloud">
    {% for page in pages|sort_by("time")|reverse %}
    {% if (page.id starts with "blog/tags") and not page.hidden %}
        <span class="list"><a href="{{ page.url }}">{{ page.title }}</a></span>
    {% endif %}
    {% endfor %}
</section>

The tags are displayed well. But when I try to do the same in the tags.twig theme,

<section id="tag_cloud">
    {% for page in pages|sort_by("time")|reverse %}
    {% if (page.id starts with "blog/tags/") and not page.hidden %}
        <span class="list"><a href="{{ page.url }}">{{ page.title }}</a></span> 
    {% endif %}
    {% endfor %}
</section>

I do not see the tag cloud although the rest of the page is displayed correctly. I tied the following too with no success,
{% if (page.id starts with "{{ base_url }}/blog/tags/") and not page.hidden %}
{% if (page.id starts with "blog/tags/{{ page.meta.tags|lower }}") and not page.hidden %}
{% if (page.id starts with "{{ base_url }}/soch/tags/{{ page.meta.tags|lower }}") and not page.hidden %}

Indeed, the tag pages are in the blog/tags/ folder. I am not sure what is the reason for the failure here.

The issue here is that the tags pages are trying to show two different page listings using the pages array. The Filter header in the tags pages makes the plugin filter the pages array so that it only contains pages with that tag. That means we can't use the pages array as a list of all pages to e.g. display a tag cloud. That's a drawback of the plugin as it's currently built and something that could be improved upon.

Ah, I see. I tried removing the Filter from the tag pages and noticed that the tag cloud is show and for obvious reasons, the posts lists are not filtered, but all.

As you said, this is certainly something that can be improved upon later. Thanks anyway.