欢迎光临
请一秒记住我们的网址:www.xinfans.com !

WordPress调用特定条件的文章列表

wordpress主题开发中会遇到需要在特定页面中调用指定的文章或文章列表,接下来教大家如何调用WordPress特定文章列表。

调用最新文章:

<?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; ?> 

在需要调用特定文章列表的页面使用如上代码,就可以达到效果啦。

赞(20) 打赏
文章名称:WordPress调用特定条件的文章列表
文章链接:https://www.xinfangs.com/948.html
版权声明:本站各种资源及插件大部分为网络搜集而来,如有侵犯版权的,请留言,本站将予以删除改正。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

作者推荐

  •     小主,您等等奴家嘛。

评论 1

评论前必须登录!

 

  1. #0

    测试

    Hi,小杨哥10个月前 (08-01)

请一秒记住我们的网址:www.xinfangs.com.

去投稿去留言

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏