Recent Blog Posts on page and full list of Blog Posts on another page
I'm trying to create a page that shows the 4 most recent blog posts by tag. And, on that same page, I want to show 3 tags (each with the 4 most recent blog posts associated with that tag). Below each one of those sections I want a button that will link to a full list of all blog posts for that tag.
Below is the code I currently have.
Here is the code to get the 4 most recent posts for the tag "optimization."
{% set topic_posts = blog_recent_topic_posts('default', 'optimization', 4) %} {% for topic_post in topic_posts %}
My Content {% endfor %}
And here is the link I set to get all of the blog posts tagged optimization.
<a href="{{ blog_tag_url('default', 'optimization') }}">View all posts</a>
The issue I'm having is when I click on the "View all posts" button it goes to the correct URL (website/tag/optimization) but it only gets the 4 latest posts instead of getting ALL of them.
Is there a way to have the button get a list of all posts for the specified tag?
I've tried your code(at least the part(s) you've posted) and they've worked for me. The only thing I've changed was the tag, as I have no posts in my blog with your tag – everything works fine.
Here are some screens of my code and the results
the code you've provided. I've only changed the tag and added some p-tags for 'beauty'
the preview looks like this
there are 4 "My Content", because it's limited to 4.
By clicking on 'View all posts' I see all posts I've tagged with the 'Insider'-tag(there are 5 in total)
Could you provide your whole code and an URL? Maybe there is something else what's needed to be optimized 🙂
Recent Blog Posts on page and full list of Blog Posts on another page
Thank you for the replies. I think the issue I have is I'm trying to do too many things with one template.
When you go to the blog I want a page that shows 5 of the latest posts for each Tag/Category I've created. And then have a button that will allow the person to click and see ALL of the posts in that Tag/Category.
Is that doable with a single template? Here is some code I have that gets me all of the posts:
Recent Blog Posts on page and full list of Blog Posts on another page
Apologies if I'm confusing this, haha.
The solution I was going to use is just to have the blog show all posts and then make individual landing pages that will be specifc for each Tag I've created. And, on those landing pages, just get the 5 latest posts.
That works, just was hoping there was an easier way to keep it all contained in the blog.
it took a time, but I think I could figure it out.
Could you please try the following code and tell me, if it works?
<!-- define your Tags here; you can add as much tags as you want --> {% set optimizations = blog_recent_topic_posts('default', 'optimization', 4) %} {% set its = blog_recent_topic_posts('default', 'it', 4) %}
<div class="blog-section"> <div class="blog-listing-wrapper cell-wrapper"> <div class="blog-section"> <div class="blog-listing-wrapper cell-wrapper"> {# simple_list_page indicates the "blog/all" page, which is a list of links to every blog post #} <div class="post-listing{% if simple_list_page %}-simple{% endif %}"> <section id="latest_news"> <div class="container"> <div class="container"> <div class="row"> <div class="span12"> <!-- define the list view for the first tag here --> {% for optimization in optimizations %} <li> <a href="{{ content.absolute_url }}" class="photo"> <div style="background:url('{{ content.featured_image }}') no-repeat center center / cover;"></div> </a> <h4>{{ content.name }}</h4> <p>{{ content.post_summary|striptags|truncate(160, breakword=False, end='...') }}</p> <a href="{{ content.absolute_url }}">Read More</a> </li> {% endfor %} <!-- define the list view for the second tag here --> {% for it in its %} <li> <a href="{{ content.absolute_url }}" class="photo"> <div style="background:url('{{ content.featured_image }}') no-repeat center center / cover;"></div> </a> <h4>{{ content.name }}</h4> <p>{{ content.post_summary|striptags|truncate(160, breakword=False, end='...') }}</p> <a href="{{ content.absolute_url }}">Read More</a> </li> {% endfor %} </div> </div> </div> {% endfor %} <div class="container"> <div class="row"> <div class="span12"> <a href="{{ blog_tag_url('default', 'optimization') }}" class="button">VIEW OPTIMIZATION POSTS</a> | <a href="{{ blog_tag_url('default', 'it') }}" class="button">VIEW IT POSTS</a> </div> </div> </div> </div> {% if not simple_list_page %} <section> <div> <div class="blog-pagination center"> {% if last_page_num %} <a class="previous-posts-link" href="{{ blog_page_link(last_page_num) }}">Previous Posts</a> {% endif %} <a class="all-posts-link" href="{{ group.absolute_url }}/all">View All Posts</a> {% if next_page_num %} <a class="next-posts-link" href="{{ blog_page_link(next_page_num) }}">Next Posts</a> {% endif %} </div> {% endif %} </div> </section> {% else %} <section> <div class="container"> <div class="col_center"> <h2>{{ content.name }}</h2> <img src="{{ content.featured_image }}"> <h4>{{ content.updated|datetimeformat('%B %e, %Y') }}</h4> {{ content.post_body }} <a href="{{ content.next_post_slug }}">Next Article: {{ content.next_post_name }}</a> </div> </div> </section> {% endif %}
Thanks
Anton
Did my post help answer your query? Help the Community bymarking it as a solution