WordPress如何无插件调用最新、热门、随机文章

互联网 20-1-11

WordPress如何无插件调用最新、热门、随机文章?

WordPress无插件调用最新、热门、随机文章实例代码

推荐:《wordpress教程

WordPress无插件调用最新、热门、随机文章,具体实现代码如下,感兴趣的朋友可以参考下哈,希望对大家在新闻调用上有所帮助

调用最新文章:

代码如下:

<ul>  <?php $post_query = new WP_Query(‘showposts=10′);  while ($post_query->have_posts()) : $post_query->the_post();  $do_not_duplicate = $post->ID; ?>  <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>  <?php endwhile;?>  </ul>

调用热门文章:

代码如下:

<ul>  <?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(); ?>  <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’ => 10);  $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(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>  <?php endwhile; ?>  </ul>

以上就是WordPress如何无插件调用最新、热门、随机文章的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: WordPress
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:wordpress优化指南是什么

相关资讯