新闻中心

wordpress调用特定文章列表的技巧分享

作者 / 无忧主机 时间 2014-08-25 17:45:12

Wordpress这个博客程序相比大家并不陌生。之前无忧主机小编也分享过不少关于这个开源程序的问题处理和经验分享。今天无忧主机小编也给大家带来的是更深一点的知识。 在 wordpress主题制作开发中经常会需要在特定的页面中调用出指定的文章或文章列表, 接下来无忧主机小编就教大家使用如何调用出 wordpress文章列表 。 1、首先调用网站最新文章: <?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; ?>   2、调用随机文章: <?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; ?>   3、调用某个分类下的最新文章: <?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; ?>   4、排除某个分类下的文章: <?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; ?> 以上就是文章列表的大概调用方法,可以将例子中的代码结合起来达到您自己需要的效果。感谢大家对无忧主机长期以来的支持,如果您需要空间可以联系QQ:340555006   无忧主机相关文章推荐阅读: WORDPRESS多站点功能教程 WORDPRESS评论头像不显示问题解决办法 WORDPRESS 网站后台自动压缩PNG格式图片方法 WORDPRESS限制会员或者游客评论内容的最小字数

本文地址:https://www.51php.com/wordpress/15920.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服