WP_query to put a post from one category in sidebar?
-
Hello, everyone!
I’m tweaking a template in an attempt to put the latest post from a specific category into the sidebar, as kind of a “featured post.” From the codex, I understand that I should use wp_query to do this because it’s happening outside the_loop.
The code I’m trying to use is
<?php $videoPosts = new WP_Query('cat=7&showposts=1'); ?> <?php while ($videoPosts->have_posts()) : $videoPosts->the_post(); ?> <?php the_content(); ?> <?php endwhile; ?>
If I remove the “cat=7” from the first line, it works–it displays the latest post made (not specified by category).
However, once I put the “cat=7” into the code, it stops working altogether; nothing shows up at all, from any category.
I’ve been through the codex and the forums, but I can’t figure out where I’m going wrong. I’ve also tried using “category_name” instead of “cat”, replacing the variable with the name of the category. No luck there, either.
Can a kind guru please tell me what I’m doing wrong?
- The topic ‘WP_query to put a post from one category in sidebar?’ is closed to new replies.