对于我们开发wordpress主题来说wordpress调用指定分类是我们常用的一种方式,而对广大的wordpress爱好者同样wordpress调用指定分类也是需求非常高的,如果您正在学习wordpress主题开发那么这个wordpress调用指定分类wordpress教程正好能满足您的需要。下面由瑞课小编我来告诉您wordpress调用指定分类的几种方式:
首先第一个wordpress调用指定分类常用方法:
<ul>
<?php query_posts('cat=1&showposts=5'); ?>//cat是要调用的分类ID,showposts是需要显示的文章数量
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
第二种wordpress调用指定分类方法:
<ul>
<?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>
第三种wordpress调用指定分类方法:
<?php
$cat_id = 12; //指定分类ID
$args = array(
'cat' => $cat_id, //分类ID
'orderby' => 'ID',
'order' => 'ASC'
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
?>
<div id="leftcolumn">
<h2 class="left"><?php echo $cat_name;?></h2>
<a target="_blank" href="<?php the_permalink();?>" ><?php echo $post->post_title;?></a>
<?php
endwhile;
wp_reset_query(); //重置查询
?>
以上wordpress调用指定分类常用手段介绍完毕,如果您还想学习更多点击下面翻页,我们了解下wordpress调用指定分类其它的相关知识。wordpress读取指定分类文章可以按照以下参数来读取:
1 2

