CMS Development

mfarnham
Contributor | Diamond Partner
Contributor | Diamond Partner

Blog Simple List Page

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

 

  DMG_2019_Blog_Lander.jpg

0 Upvotes
10 Replies 10
stefen
Key Advisor | Partner
Key Advisor | Partner

Blog Simple List Page

@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 %}

More info here.

 

 

Stefen Phelps, Community Champion, Kelp Web Developer
mfarnham
Contributor | Diamond Partner
Contributor | Diamond Partner

Blog Simple List Page

For some reason when it displays the most topic posts it repeats them 5 times.  Not sure what I am missing. Thanks

 

You can view it here.

 

{% for content in contents %}
{% if not simple_list_page %}
{% if topic %}
{{ content.name }}


{% else %}

{# put the following snippet in your blog loop at the top of the page #}

{% if loop.first %}
{% set first_post_url = content.absolute_url %}


<div class="featured_blog_post_wrapper">
<a href="{{ content.absolute_url }}">
<div class="featured_blog_post_area">
{# {% if content.widgets.blog_image.body.src %} #}
<div class="featured-image">
<img src="{{ content.featured_image }}" class="lazy" alt="{{ content.name }}">
</div>
{# {% endif %} #}

<div class="post-box-inner">
<h4>Featured Article</h4>

<h3>{{ content.name }}</h3>

<span class="btn_read_more">Read More</span>
</div>
</div> <!--end featured_blog_post_area -->
</a>
</div> <!--end featured_blog_post_wrapper -->

{% endif %}

<h2>
Digital Marketing >
</h2>

{% 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 %}

{% endif %}
{% endif %}
{% endfor %}

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Blog Simple List Page

@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 %}
Stefen Phelps, Community Champion, Kelp Web Developer
mfarnham
Contributor | Diamond Partner
Contributor | Diamond Partner

Blog Simple List Page

Just not sure why it is showing the same post multiple times.

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Blog Simple List Page

@mfarnham you need to put the topic posts loop outside of the main blog loop (the for content in contents).

Stefen Phelps, Community Champion, Kelp Web Developer
mfarnham
Contributor | Diamond Partner
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.  

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Blog Simple List Page

@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 %}
Stefen Phelps, Community Champion, Kelp Web Developer
0 Upvotes
mfarnham
Contributor | Diamond Partner
Contributor | Diamond Partner

Blog Simple List Page

Thanks for you help!

0 Upvotes
mfarnham
Contributor | Diamond Partner
Contributor | Diamond Partner

Blog Simple List Page

Is there a way that you can exclude the the most recent one if it is shown up top? So it would show 2-4.

 

Thanks

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Blog Simple List Page

@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 %}

 

Stefen Phelps, Community Champion, Kelp Web Developer