Display latest post from category *with slug*
-
I’ve seen this topic here about how to display the last post from a particular category and I’d like to do this but using categories with slugs rather than IDs. I’ve got this request here:
<h4 class="center">This Week</h4> <?php $cat_id = 0; $latest_cat_post = new WP_Query( array('posts_per_page' => 1, 'category__in' => array($cat_id))); if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post(); ?> <h4><?php the_title(); ?></h4> <?php the_content(); ?> <?php endwhile; endif; ?>
I’d like to know how to either find out the ID of categories with slugs switched on, or how to have this request parse a slug. FYI, the page this is going into is actually a specific category template itself.
Structure:
root
– events
|_ event-reviews
|_ event-previews
– listingsI’m currently altering the category-events template and trying to have it show the last listings post in the sidebar.
I hope that’s enough context. Thanks in advance.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Display latest post from category *with slug*’ is closed to new replies.