CMS Development

toddlyda
Member

Show 1 post from a specific tag

SOLVE

I'm trying to simply display the most recent post in the specific tag "branding". I'm using the following but get nothing returned.

 

{% set tag_posts = blog_recent_tag_posts('default', branding, 1) %}
{% for tag_post in tag_posts %}
<div class="post-title">{{ tag_post.name }}</div>
{% endfor %}

0 Upvotes
1 Accepted solution
toddlyda
Solution
Member

Show 1 post from a specific tag

SOLVE

I got this to work:

 

<h4>Branding</h4>
{% set brands = blog_recent_topic_posts('default', 'branding', 1) %}
{% for brand in brands %}
<div class="row">
<div class="col-sm-4">
<img src="{{ brand.featured_image }}" alt="{{ brand.name }}">
</div>
<div class="col-sm-8">
<h3><a href="{{ brand.absolute_url }}">{{ brand.name }}</a></h3>
<p>{{ brand.post_summary|striptags|truncate(160, breakword=False, end='...') }}</p>
<a href="{{ brand.absolute_url }}">Read More</a> </li>
{% endfor %}
</div>
</div>

 

This includes my extra markup. Looks like I was needing to use blog_recent_topic_posts instead.

View solution in original post

4 Replies 4
CClaro
Participant

Show 1 post from a specific tag

SOLVE

Thanks @toddlyda!

0 Upvotes
toddlyda
Solution
Member

Show 1 post from a specific tag

SOLVE

I got this to work:

 

<h4>Branding</h4>
{% set brands = blog_recent_topic_posts('default', 'branding', 1) %}
{% for brand in brands %}
<div class="row">
<div class="col-sm-4">
<img src="{{ brand.featured_image }}" alt="{{ brand.name }}">
</div>
<div class="col-sm-8">
<h3><a href="{{ brand.absolute_url }}">{{ brand.name }}</a></h3>
<p>{{ brand.post_summary|striptags|truncate(160, breakword=False, end='...') }}</p>
<a href="{{ brand.absolute_url }}">Read More</a> </li>
{% endfor %}
</div>
</div>

 

This includes my extra markup. Looks like I was needing to use blog_recent_topic_posts instead.

MMorisette
Participant

Show 1 post from a specific tag

SOLVE

You just saved me a bunch of time. Much appreciated.

sharonlicari
Community Manager
Community Manager

Show 1 post from a specific tag

SOLVE

Thank you for sharing this @toddlyda 🙂


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes