2011-08-06 14 views
1

私は次のコードを使用して自分のホームページに記事を表示していますが、2〜3つのカテゴリに制限したいと思います。フィードを特定のカテゴリのみに限定する

<?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; ?>&amp;h=170&amp;w=255&amp;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 &raquo;', '% Comments &raquo;'); ?></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 &raquo;</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 bloginfo('template_directory'); ?>/js/timthumb.php?src=<?php echo $image_url; ?>&amp;h=120&amp;w=209&amp;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 &rarr; ]</a></span> 

</div> 
<?php } ?><?php $i++; ?><?php endwhile; $i=0; ?> 
</div> 

答えて

1

あなたが容易にするためquery_posts()関数を使用することができ、ここで昇順とページあたり5回の記事では、category_ids 1,3および5からの投稿を引っ張っする方法の例です:

query_posts('cat=1,3,5&order=ASC&posts_per_page=5'); 

詳細はこちらhttp://codex.wordpress.org/Function_Reference/query_posts

使用しているWP_Queryオブジェクトは、引数の点ではクエリポストとほぼ同じです。

+0

こんにちはLiamさん、ありがとうございました。これは上に表示されたコードに適合するのでしょうか、それとも書き直す必要がありますか? – toomanyairmiles

関連する問題