首页 论坛 WordPress调用指定分类下热门文章
帖子详情

第一种:Wordpress调用指定分类下热门文章,通过评论量进行排序。代码如下:

 <?php $rand_posts = get_posts('numberposts=5&category=2&orderby=comment_count');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 34, ''); ?></a></li>
  <?php endforeach;?>

第二种:Wordpress调用指定分类下热门文章,通过浏览量进行排序。

<?php if (have_posts()) : ?>
<?php query_posts('cat=5' . $mcatID. '&caller_get_posts=1&showposts=16&v_sortby=views'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>

注意:wordpress程序调用按照浏览量来调用某一个分类下的热门文章代码:(注意使用这种方式调用热门文章,网站必须安装wordpress浏览量插件)

第三种:wordpress程序调用按照评论量来调用某一个分类下的热门文章(热评文章)代码:

<?php
$post_num = 10; // 设置调用条数
$args = array(
'post_password' => '',
'post_status' => 'publish', // 只选公开的文章.
'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><?php comments_number('0', '1', '%' );?> 次评论: <br><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php } wp_reset_query();?>

版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.52diyhome.com/forum/65999.html

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    资源总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

资源在于分享,创作来源想象