Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Filter Blogs by topic / category?
New Contributor
Jun 8, 2017 7:57 PM
I'm trying to filter my blog listing page by topic when desired. I know I'm probably over thinking this, but for whatever reason I cant figure out how to get the listing page to show only the desired topic chosen. I just added the {% if topic %} statement to see if that would fix my propblem, but it wont show the topic posts - it's left blank as seen in the screenshot below.
Default listing
When a topic is selected
Here is my HTML markup
{% set posts = blog_recent_posts('XXXX', 10) %}
{% set topic_posts = blog_recent_topic_posts('XXXX', topic.slug, 10) %}
{% set topics = blog_topics('XXXX', 10) %}
<section class="section-basic post-listing{% if simple_list_page %}-simple{% endif %}">
<div class="container">
<div class="row">
<div class="col left-content" data-settings="size-8">
{% if topic %}
<h2 class="section-title">Posts about {{ page_meta.html_title|replace(' | ', '') }}</h2>
{% else %}
<h2 class="section-title">Our latest stories</h2>
{% endif %}
<div class="divider horizontal stubby"></div>
<div class="row vertical">
{% if topic %}
{% for content in topic_posts %}
<article class="blog-list-wrapper">
<div class="blog-thumbnail-image"><a class="no-styling" href="{{ content.absolute_url }}"><img src="{{ content.featured_image }}" alt="{{ content.featured_image_alt_text }}" width="245"></a>
</div>
<div class="blog-post-summary">
<h2 class="blog-listing-title"><a class="no-styling" href="{{ content.absolute_url }}">{{ content.name }}</a></h2>
<p>{{ content.post_list_content|safe }}</p>
<a href="{{ content.absolute_url }}">Continue reading</a>
<div>
{% if content.topic_list %}
{% for topic in content.topic_list %}
<a class="topic-link" href="{{ group.absolute_url }}/topic/{{ topic.slug }}"><div class="category">{{ topic.name }}</div></a>{% if not loop.last %}{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
</article>
{% endfor %}
{% else %}
{% for content in posts %}
{% if not simple_list_page %}
<article class="blog-list-wrapper">
<div class="blog-thumbnail-image"><a class="no-styling" href="{{ content.absolute_url }}"><img src="{{ content.featured_image }}" alt="{{ content.featured_image_alt_text }}" width="245"></a>
</div>
<div class="blog-post-summary">
<h2 class="blog-listing-title"><a class="no-styling" href="{{ content.absolute_url }}">{{ content.name }}</a></h2>
<p>{{ content.post_list_content|safe }}</p>
<a href="{{ content.absolute_url }}">Continue reading</a>
<div>
{% if content.topic_list %}
{% for topic in content.topic_list %}
<a class="topic-link" href="{{ group.absolute_url }}/topic/{{ topic.slug }}"><div class="category">{{ topic.name }}</div></a>{% if not loop.last %}{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
</article>
{% else %}
{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
Note: if it matters I'm using a different HTML listing page then the post page.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content