My latest WordPress related issue came about because I mocked up what I thought was a good idea in photoshop, and then after I cut it up and tried to implement it I found out it was not so easy….
Okay, so what I wanted to do was have the latest post “featured” that is above the rest of the posts spanning the entire width of the area ( while the rest of the posts floated left of the sidebar ). And of course this would only happen on the homepage. Sounds simple right?
Well it turns out it in WordPress theming it is not so simple, but you can see how I hacked it up here:
What you have to do is first, the standard WordPress homepage trick:
<?php if(is_home() ) { ?>
//do this if it is the homepage
<?php } else { ?>
// do this if it is not the home page
<?php } ?>
and then what happens is that you need to have 2 WordPress loops, like so:
<?php $my_query = new WP_Query('showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
// first loop stuff here
<?php endwhile; ?>
In that previous loop ( which goes inside the home page only code provided earlier ) you stick code that you want to run for the first post, so you need the entry, the title, date, etc.
Now, in the next WP loop you’ll have your normal loop stuff but it needs a little modification because you don’t want to repeat the first post.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); if( $post->ID == $do_not_duplicate) continue; update_post_caches($posts); ?> // the regular loop stuff <?php endwhile; ?>
Whew! While WordPress is a dead simple CMS for end users, sometimes it makes developers jump through hoops. I am not sure if this will help anyone else understand what is going on, but I hope that it sheds some light on the issue – as this site: unintentionallyblank helped me.
