Styling the Latest Post

31 May, 2005 | TipsWordpress TipsTechVfd

On the Digerati Peninsula home page I use a modified version of the recent posts plugin by MtDewVirus, I also set $more = 1 so it shows the full post and not just the part up to the more tag and I also add exit; after I call the footer so as to stop the loop after one iteration.

I have added spaces at the start or many of the tags so they show up instead of getting parsed, you need to remove these spaces to use the code


<?php if (have_posts()) : while (have_posts()) : the_post(); $more = 1; ?> // the $more = 1 tell WP to ingore the more tag so showing all of the post
<h1><?php if ('/' == $_SERVER['REQUEST_URI'] || '/index.php' == $_SERVER['REQUEST_URI']) { ?> Latest Entry: <? } ?>
<? if ($pagename) { the_title(); } else { ?><a href="" rel="bookmark"><?php the_title(); ?><? } ?>
<?php the_content(); ?>
<? if (!$pagename) { ?>
<p class="details">This entry was posted on <strong><?php the_date('jS F Y','','',true); ?> </strong> in <?php the_category(','); ?><?php if (!$single) { ?> and has had <a href="" title="Link to this entries comments"><?php comments_number('No Comments','1 Comment','% Comments',''); ?></a> so far <?php }?>. <?php if ($single) { ?> <a href="/wp-content/themes/digerati/wp-print.php?p=<?=the_ID()?>">Format this page for printing <?php } ?>
<p class="previous"><?php previous_post('« %','previous entry','no'); ?> </p>
<p class="next"><?php next_post('% »','next entry','no'); ?>
<? } ?>
<div style="clear:both">
<?php if ($single) { comments_template(); /*include('comments.php');*/ } elseif (!$pagename) { ?>
<div id="latestlist">
<p>FIVE LATEST ENTRIES</p>
<dl>
<?php get_recent_posts(5, '<dt>', '', true, 1, true); ?> // This is the call to the plugin which displays the recent entries
</dl>
</div>
<? include('footer.php'); exit; ?> // the exit; call stops the loop after 1 iteration so you only get one post

Alternatively, on Viewfinder Design I call the loop as normal but add a test variable ($ctemp = 0) after the have_posts() : call and then check it and apply a different style if it equals 0 (i.e. for the first post) than I do for any of the remaining posts.


if (have_posts()) :
$ctemp = 1; // This is my test variable
while (have_posts()) : the_post();
//if (strtolower(get_cat_name($id)) == 'news') { if ($ctemp == 1) { // Basically, if this is the first post, apply this style
print ("<div id="latest">n");
} else { // Otherwise, apply this style - this could easily be adapted to call different templates tags (i.e. to show only the title and excerpt)
print ("<div class="post">n");
}
?>
<h3><a href="" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
<div class="date">
<ul>
<li class="day"><?php the_time('j') ?></li>
<li><?php the_time('M') ?></li>
</ul>
</div>
<?php if ($ctemp == 1) { // check if the first post, if so
print ("<div id="latebot">n"); //do this
} $ctemp++; ?> // then +1 to the text variable
</div> // otherwise just close the div
<?php //} ?>
<?php endwhile; ?>