Limiting feed to only certain categories
I'm using the following code to pull articles up for display on my homepage, i'd like to limit it to only two or three categories - can anyone point me in the right direction?
<?php
$i = 1;
$my_categories = get_option('of_news_page');
$wp_query = new WP_Query("cat=' . $my_categories . '&posts_per_page=14");
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];?>
<?php if($i==1) { ?>
<div class="featured_single">
<div class="featured_single_image">
<?php if($image_url) { ?><a class="image_article" href="<?php the_permalink(); ?>"><img src="<?php echo bloginfo('template_directory'); ?>/js/timthumb.php?src=<?php echo $image_url; ?>&h=170&w=255&zc=1" alt="" /></a><?php } ?>
<div class="clear"></div>
<span>Posted in : <?php the_category(', '); ?></span>
<span><?php comments_popup_link('No comments yet', '1 Comment »', '% Comments »'); ?></span>
</div>
<div class="featured_single_text">
<span><?php the_time('M j, Y') ?></span>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php wpe_excerpt('wpe_featured_single'); ?>
<p><a href="<?php the_permalink(); ?>">Read More »</a></p>
</div>
</div>
<div class="clear"></div>
<div id="featured-posts-news">
<?php } elseif($i>1 && $i<6) { ?>
<div class="featured-post-news-container clearfix">
<?php if($image_url) { ?><a href="<?php the_permalink(); ?>"><img src="<?php echo blog开发者_如何学Pythoninfo('template_directory'); ?>/js/timthumb.php?src=<?php echo $image_url; ?>&h=120&w=209&zc=1" alt="" /></a><?php } ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<span><?php the_time('M j, Y') ?></span>
<?php wpe_excerpt('lotf_news_page'); ?><span class="news-morelink"><a href="<?php the_permalink(); ?>">[ Read More → ]</a></span>
</div>
<?php } ?><?php $i++; ?><?php endwhile; $i=0; ?>
</div>
You can use the query_posts() function for ease, here is an example of how to pull posts from category_ids 1,3 and 5, in ascending order and 5 posts per page:
query_posts('cat=1,3,5&order=ASC&posts_per_page=5');
You can find out more here: http://codex.wordpress.org/Function_Reference/query_posts
Note, the WP_Query object you are using works in much the same way as query posts, in terms of arguments that is.
精彩评论