wordpress调用最新、热门、随机文章

wordpress调用最新、热门、随机文章

调用最新文章:

<?php query_posts('showposts=14'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a title=”<?php the_title(); ?>” href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

调用热门文章:

<ul>
<?php
$post_num = 14; // 设置调用条数
$args = array(
   'post_password' => ”,
   'post_status' => 'publish', // 只选公开的文章.
   'post__not_in' => array($post->ID),//排除当前文章
   'caller_get_posts' => 1, // 排除置頂文章.
   'orderby' => 'comment_count', // 依評論數排序.
   'posts_per_page' => $post_num
);
 $query_posts = new WP_Query();
 $query_posts->query($args);
 while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
  <li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php } wp_reset_query();?>
</ul>

调用随机文章:

<ul>
<?php
  global $post;
  $postid = $post->ID;
  $args = array( 'orderby' => 'rand', 'post__not_in' => array($post->ID), 'showposts' => 14);
  $query_posts = new WP_Query();
  $query_posts->query($args);
?>
<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

1
原文
蜗牛不带伞
蜗牛不带伞
发表于2018-04-05 5:05
标签 wordpress优化文章 归档于 wordpress