wordpress调用随机文章

2022年9月2日13:48:34 发表评论
微信搜一搜 ts小陈

wordpress调取随机文章主要有以下两种循环方式:

wordpress调用随机文章

方法一:foreach循环

  1. <?php
  2. $rand_posts = get_posts('numberposts=10&orderby=rand');
  3. foreach$rand_posts as $post ) :
  4. ?>
  5. <!–下面是你想自定义的Loop–>
  6. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  7. <?php endforeach; ?>

 

方法二:while循环

  1. <?php
  2. $post_num = ''.sc_tsxcc('ts_syshulaing').''// 设置调用条数
  3. $args = array(
  4. 'caller_get_posts' => 1, // 排除置顶文章.
  5. 'orderby' => rand, // 依评论数排序.
  6. 'posts_per_page' => $post_num
  7. );
  8. query_posts($args); ?>
  9. <?php while (have_posts()) : the_post(); ?>
  10. <li>
  11. <a target="_blank" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="title"><?php the_title(); ?></a>
  12. </li>
  13. <?php endwhile; ?>

tsxc主题使用的第二种方法,后台设置调取随机文章的数量。

这2种方法都能实随机文章的调用。

小陈号卡
ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容