On the simple listing page I need to show the most recent blog post but then below show the 3 most recent blog posts per category(attached an image). Each category would be an array of certain topics. For the regular topic listing page we are keeping the current look. I can't seem to figure out how to show the most recent posts per category. Any help would be appreciated. Thanks
@mfarnham the easiest way would be to use the "blog_recent_topic_posts" function. As you can probably get from the name, it let's you get the most recent posts by a specific topic like so:
{% set topic_posts = blog_recent_topic_posts('default', 'marketing-tips', 5) %}
{% for topic_post in topic_posts %}
<div class="post-title">{{ topic_post.name }}</div>
{% endfor %}
{% set topic_posts = blog_recent_topic_posts('default', 'digital-marketing', 4) %} {% for topic_post in topic_posts %} {# put the following line in each topic blog loop #} {% unless content.absolute_url = first_post_url %} <div class="post-title">{{ content.name }}</div> {% endunless %} {% endfor %}
@mfarnham since your loop is looking for "topic_post" you should update the code to:
{% for topic_post in topic_posts %}
{# put the following line in each topic blog loop #}
{% unless topic_post.absolute_url == first_post_url %}
<div class="post-title">{{ content.name }}</div>
{% endunless %}
{% endfor %}
Feb 18, 20198:25 PM - edited Feb 21, 20198:38 AM
Contributor | Diamond Partner
Blog Simple List Page
@stefen I took the topic posts loop out of the blog loop and now it is not excluding the most recent post. Everything is working except for the the most recent post.
I tried to test it out to see of it was grabing the url( {{ first_post_url }} ) and it is but it only works in the blog loop. When I try to see if it will print in the topic loop nothing shows up.
@mfarnham ah, okay. You may have to manually filter your blog loop then. So something like:
{% for content in contents %}
{% if loop.first %}
markup for the first {{ content.name}} post goes here...
{% endif %}
{% if content.topic_list is containing "cool_topic" %}
all posts with the topic "cool_topic"
{% endif %}
{% endfor %}
@mfarnham you could set a variable of the first post's URL then use an if statement to check if the post has that URL in each of the topic for loops. Something like following:
{# put the following snippet in your blog loop at the top of the page #}
{% if loop.first %}
{% set first_post_url = post.absolute_url %}
{% endif %}
{# put the following line in each topic blog loop #}
{% unless post.absolute_url = first_post_url %}
{{ post.name }}
{% endunless %}