WordPress调用最新,随机,热门,指定分类代码汇总

关于WP文章调用方法,包括调用最新,指定分类,随机,热文等代码,经测试,支持最新版Wordpress。

1调用最新文章

  // 显示篇数和排除分类

2调用指定分类文章

    $args=array( 'cat' => 1, // 分类ID 'posts_per_page' => 10, // 显示篇数 ); query_posts($args); if(have_posts()) : while (have_posts()) : the_post(); ?>

3调用整站随机文章

    5, 'orderby' => 'rand', 'post_status' => 'publish' ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?>

4调用同分类随机文章

    $category){ $catid = $category->term_id;} $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); // 显示篇数 $query_posts = new WP_Query(); $query_posts->query($args); while ($query_posts->have_posts()) : $query_posts->the_post();?>

5调用整站热门文章(按评论数)

    ”, ‘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(); ?>

本文来自投稿,不代表科技代码立场,如若转载,请注明出处https://www.cwhello.com/14348.html

如有侵犯您的合法权益请发邮件951076433@qq.com联系删除

(0)
上一篇 2019年10月30日 15:57
下一篇 2019年10月30日 16:09

相关推荐

联系我们

QQ:951076433

在线咨询:点击这里给我发消息邮件:951076433@qq.com工作时间:周一至周五,9:30-18:30,节假日休息