LemonStand Version 1 Has Been Discontinued
This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.
Displaying a list of recent posts
While the blog:archive action allows to display all recent blog posts with pagination, you may need a simple solution for displaying a fixed number of recently published blog posts on the website sidebar or on the home page. You can use the list_recent_posts() method of the Blog_Post class to load a list of recent posts. This method has a single parameter - the number of posts to load. Below is a code example, which loads 5 recent blog posts and displays them as a list:
<? $post_list = Blog_Post::list_recent_posts(5) ?>
<ul>
<? foreach ($post_list as $post): ?>
<li>
<h3><?= h($post->title) ?></h3>
<p>
Published by <?= h($post->created_user_name) ?>
on <?= $post->published_date->format('%F') ?>
Comment(s): <?= $post->approved_comment_num ?>
</p>
<p><?= h($post->description) ?></p>
<p><a href="/blog/<?= $post->url_title ?>">Read more...</a></p>
</li>
<? endforeach ?>
</ul>
Previous: Tips and Tricks
Return to Tips and Tricks
