A-A+
wordpress不同文章列表的调用
wordpress 开源系统同其它的开源代码一样,经常会在开发中调用一些特定的文章列表,比如调用网站最新文章,调用随机文章列表,调用某个分类的文章等等,如果将 wordpress 做成一个新闻类的站点CMS时,这种特定文章的调用就更加频繁了,下面夏日博客总结几个调用不同文章列表较频繁的代码,在使用时方便调用。
调用网站最新文章:
<?php query_posts('showposts=10&orderby=new'); //showposts=10表示10篇 while (have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title() ?></a></li> //这里可以写成你自己需要的样式 <?php endwhile; ?>
调用随机文章:
<?php query_posts('showposts=10&orderby=rand'); //showposts=10表示10篇 while (have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title() ?></a></li> //这里可以写成你自己需要的样式 <?php endwhile; ?>
调用某个分类下的最新文章:
<?php query_posts('showposts=10&cat=1'); //cat=1为调用ID为1的分类下文章 while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?>
排除某个分类下的文章:
<?php query_posts('showposts=10&cat=-1'); //cat=-1为排除ID为1的分类下文章 while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?>
以上就是文章列表的调用方法,可以将例子中的代码结合起来达到你需要的效果。