WordPress调用特定文章列表

本站优惠券栏目展示的都是具有优惠券的淘宝热销商品,如果商品正合您意不妨先领个优惠券在去下单,您每一次领取优惠券在下单老马都会给我一点点小费,就权当对小弟的支持可好?如果栏目里没有中意的商品也别急,我还专门为您提供了一个京东淘宝优惠券网站,点击右边这个链接可以直接进入👉https://quan.yumus.cn,下单前可以在这个网站搜索一下看有没有您需要的商品,所有的交易都是在淘宝或京东完成您无需担心售后服务和交易安全,小弟在此恳请大家多多支持。

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

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