Offset posts if a condition is met
I customised my theme for http://www.dubrovnikresaturantkl.com. On the homepage, I have a Latest News & Happenings block. The main item pulls the latest post from the Highlights category and displays it with the post image. To the right of that are latest posts pulled from all categories.
The problem arises if my latest post is not in the Highlights category. The main item will show X and the latests posts will show X again (where X = the last post in the Highlights category). For my current setup – if I add a post to News, the Mother’s Day post will appear as the main item and again in the latest posts.
I want to offset the latest posts on the right, but only if the last post is something from the Highlights category. If the latest post is not in the Highlights category, then don’t offset the posts.
Here’s the code I use to offset at the moment:
<?php $latestpostOffset = new WP_Query(); $latestpostOffset->query('showposts=3&offset=1'); if ( $latestpostOffset->have_posts() ) : while ( $latestpostOffset->have_posts() ) : $latestpostOffset->the_post(); ?> <div id="post-<?php the_ID(); ?>" class="post hexcerpts"> <h3 class="entry-title"><a title="Permanent link to <?php the_title(); ?>" rel="bookmark" href="<?php the_permalink(); ?> "><?php the_title(); ?></a></h3> <div class="format_text entry-content"> <?php the_excerpt(); ?> </div> </div> <?php endwhile; endif; ?>
I hope I’m making myself clear – it’s confusing even to myself! Appreciate your help, thanks
- The topic ‘Offset posts if a condition is met’ is closed to new replies.