您好!欢迎访问千伏动力网站!
全国咨询热线:13698282878
行业新闻
您的位置: 首页 >> 行业新闻 >> 正文内容

WordPress无插件调用***新、热门、随机文章

作者:paopao 浏览量:27 时间:2025-07-23 19:55:43

  WordPress自带的widget侧边栏小工具虽然可以很轻松的调用***新文章,热门文章,随机文章。但使用侧边栏将会影响我们自定义的侧边栏效果。很多用wordpress的博客朋友都会使用其他插件来实现调用,例如中文工具箱。下面将介绍一下不用插件调用这四种类型文章的方法。

WordPress无插件调用***新、热门、随机文章


  调用***新文章:


  


  <?php $post_query=new WP_Query(‘showposts=10′);


  while ($post_query->have_posts()) : $post_query->the_post();


  $do_not_duplicate=$post->ID; ?>


  


  


  


  调用热门文章:


  


  <?php


  $post_num=10; // 设置调用条数


  $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(); ?>


  


  


  


  调用随机文章:


  


  <?php


  global $post;


  $postid=$post->ID;


  $args=array( ‘orderby’=> ‘rand’, ‘post__not_in’=> array($post->ID), ‘showposts’=> 10);


  $query_posts=new WP_Query();


  $query_posts->query($args);


  ?>


   have_posts()) : $query_posts->the_post(); ?>


  


  


  


遇到问题?请给我们留言

请填写您的电话号码,我们将回复您电话