Php 仅将提要限制为某些类别
我使用下面的代码将文章拉到我的主页上显示,我想将其限制为两到三个类别-有人能告诉我正确的方向吗Php 仅将提要限制为某些类别,php,wordpress,Php,Wordpress,我使用下面的代码将文章拉到我的主页上显示,我想将其限制为两到三个类别-有人能告诉我正确的方向吗 <?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
<?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 bloginfo('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>
张贴于:
为了方便起见,您可以使用query_posts()函数,下面是一个示例,说明如何按升序从类别ID 1、3和5中提取帖子,每页5篇帖子:
query_posts('cat=1,3,5&order=ASC&posts_per_page=5');
您可以在此处找到更多信息:
请注意,您正在使用的WP_Query对象在参数方面与Query posts的工作方式基本相同。您可以轻松使用Query_posts()函数,下面是一个示例,说明如何按升序和每页5篇文章从类别_id 1、3和5中提取文章:
query_posts('cat=1,3,5&order=ASC&posts_per_page=5');
您可以在此处找到更多信息:
请注意,您使用的WP_查询对象在参数方面与查询帖子的工作方式基本相同。Hi Liam谢谢,这是否适合上面显示的代码,还是我必须重写它?Hi Liam谢谢,这是否适合上面显示的代码,还是我必须重写它?