Displaying a Featured Post on the Home Page

A common need when using Graffiti CMS is to display a single post on the home page.  Graffiti CMS provides has a featured post flag that can be set so that the Content Management System knows which post is the currently featured post.  This is a quick and easy way to display a single specific post on the home page.  Keeping in mind that only one post can be featured at a time.

The following code demonstrates one method of displaying the featured post.  Disclaimer:  There might be a better way to handle this, but this is the method that I have used in the past and I haven’t had a reason to search for a better method.

Place the following code in the index.view file (or any .view file where applicable)

#set($post = $data.Featured())
<ul class=”post-list”>
<li class=”post-content”>
<h2 class=”post-content-title”>
<a href=”$post.Url” title=”$post.Title” rel=”bookmark”>$post.Title</a>
</h2>
<div class=”post-content-body”>
<p>
#if ($post.ImageUrl != “”)
<img style=”float: left; padding: 0px 10px 2px 0px;” src=’$macros.Link($post.ImageUrl)’ />
#end

$post.Body
</p>
</div>
</li>
</ul>
#end

Leave a Reply

Your email address will not be published. Required fields are marked *