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.
Blog post page
On the blog post page you can output a post title, content and list of post comments. Also on the post page you can display a comment form.
On the CMS/Pages page create a new page and assign it some URL, for example blog/post. Select the blog:post action on the Action tab. The blog:post action loads a blog post by its URL Title from the database and creates the $post PHP variable (an instance of the Blog_Post class). If a specified blog post cannot be found, the $post variable will have the NULL value. The code below outputs a post title, the publication date, author name, number of comments and the post content.
<? if ($post): ?>
<h2><?= h($post->title) ?></h2>
<p>
Published by <?= h($post->created_user_name) ?>
on <?= $post->published_date->format('%F') ?>
Comment(s): <?= $post->approved_comment_num ?>
</p>
<?= $post->content ?>
<? else: ?>
<h2>Post not found</h2>
<? endif ?>Displaying post comments
The Blog_Post class has 4 fields which you can use for displaying a list of comments. With these fields you can display all comments, or only approved comments.
- $comment_num - number of all blog post comments
- $approved_comment_num - number of approved blog post comments.
- $comments - a list of all blog post comments.
- $approved_comments - a list of approved blog post comments.
Below is a code example which displays a list of approved comments. The code adds a link to a comment author's website, if its address has been specified by the comment author.
<h3>Comments</h3>
<? if (!$post->approved_comment_num): ?>
<p>No comments posted so far.</p>
<? else: ?>
<ul>
<? foreach ($post->approved_comments as $comment):
$site_url_specified = strlen($comment->author_url);
?>
<li>
<p>
<? if ($site_url_specified): ?><a href="<?= $comment->getUrlFormatted() ?>"><? endif ?>
<?= h($comment->author_name) ?>
<? if ($site_url_specified): ?></a><? endif ?>
Created at: <?= $comment->created_at->format('%F') ?>
</p>
<p><?= nl2br(h($comment->content)) ?></p>
</li>
<? endforeach ?>
</ul>
<? endif ?>Next: Adding the comment form
Previous: Category page
Return to Blog module
