WordPress 调用指定(当前)分类下的文章的代码
WordPress 调用指定(当前)分类下的文章的代码
指定分类下的文章:
<?php $posts = get_posts("category=12&numberposts=10"); //category=12&numberposts=10表示列出类别为12的10条记录 //你可以wp_term_taxonomy表taxonomy字段显示不同分类, //如nav_menu=13&numberposts=10列出导航菜单为13的10条记录 ?> <?php if ($posts) : ?> <?php foreach ($posts as $post) : setup_postdata($post); ?> <h4 ><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4> <?php endforeach; ?> <?php endif; ?>
当前分类下的文章:
<?php query_posts("showposts=10&orderby=date&order=DESC"); if (have_posts()) { while (have_posts()) : the_post(); ?> <h4 ><a href="<?php the_permalink(); ?>" title="<?php the_title (); ?>" rel="bookmark"><?php the_title(); ?></a></h4> <?php endwhile; }else { include(TEMPLATEPATH . '/includes/not-found.php'); } ?>
参考:http://www.ludou.org/wordpress_query_posts.html