WordPress 主題製作開發中經常會需要在特定的頁面中調用出指定的文章或文章列表,接下來小編就來教大家如何調用出 WordPress 文章列表。

調用網站最新文章:

<?php
query_posts('showposts=10&orderby=new'); //showposts=10 表示 10 篇
while (have_posts()): the_post();
?>
<li><a href="<?php%20the_permalink();%20?>" 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%20the_permalink();%20?>" 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%20the_permalink()%20?>" 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%20the_permalink()%20?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
  <?php endwhile; ?>

以上就是文章列表的調用方法,可以將例子中的代碼結合起來達到你需要的效果。