Dynamic homepage based on interestingness
I am pretty tired of blogs that have ‘n’ number of posts aired on their landing page with a column of info on either side. That was one of the the reason I rehauled my site. I now have a situation wherein the latest 2 posts are displayed on the homepage, and if there is an announcement, the latest single post and the announcement is displayed. Its not rocket science, and its pretty easy to implement..
AIM: If there is an announcement, show only one post from theblog, otherwise show 2 posts.
THINGS TO TAKE CARE: Since I am using float boxes to show the posts, if there is a single post, the corresponding header “the latest from the blog” , and the read more article link should be within the float. When we show 2 posts, the header should be above both the posts and the “read more articles ” should be below the posts, after clearing the floats.
Click on the figure below, to get an idea.
In the last week of october, I had talked about slicing your WP pages into manageable file chunks. In the example below, the “inc_showsinglepost.php” refers to the display of a single post. Note how I call it within any loop I use. I dont have to be bothered about what is displayed, as I have set the content to show an excerpt everywhere, and all content when shown in a single page.
$post = "";
$anyannouncement="no";
query_posts(’cat=35 & showposts=1′);
if (have_posts()) :
$post = $posts[0];
while (have_posts()) : the_post();
$goAwayDate = time() - (60 * 60 * 24 *10);
$postDate = get_the_time(’U');
if($postDate < $goAwayDate) {
} else {
?>
<p class="half">
endwhile; endif;
?>
$post=""; $count=0;
if ($anyannouncement=="yes") {query_posts("cat=-35"."& showposts=1"); }
else {query_posts("cat=-35"."& showposts=2"); }
if (have_posts()) :
?>
<p class="lilnotes thelatestblogpost">absolutely the latest post</p>
<p class="half"> </p>
<p class="lilnotes thelatestblogpost">absolutely the latest post
<a href="http://www.chilligavva.com/wp-admin/%3C?php%20echo%20get_settings%28%27home%27%29;%20?%3E/index.php/category/general" class="more-entries">read more articles?</a>
<p class="clear">
<a href="http://www.chilligavva.com/wp-admin/%3C?php%20echo%20get_settings%28%27home%27%29;%20?%3E/index.php/category/general" class="more-entries">read more articles?</a>
<p class="clear"> </p>
<p class="clear"> </p>
I check to see whether there is an announcement. if there is, I also check to see if its less than 10 days old. Only then, the announcement will be showed. Otherwise, the variable “$anyannouncement” is set to “no”. Then 2 latest posts are showed in the home page. Since the entire code is my “home.php” file, it is what is showed in the home or landing page..
