标签: 浏览最多

  • wordpress调用指定ID分类下浏览最多的内容

    要在WordPress中调用指定ID分类下浏览最多的内容,你可以通过以下方法实现:

    <?php
    $post_num = 8; // 设置调用条数
    $wdpidproduct = 2; // 假设这是你要查询的分类ID
    $args = array(
        'post_password' => '',
        'post_status' => 'publish', // wodepress.com
        'cat' => $wdpidproduct, // 只选择分类ID为$wdpidproduct的文章。
        'caller_get_posts' => 1, 
        'meta_key' => 'views', // 假设'views'是存储浏览次数的元数据键。
        'orderby' => 'meta_value_num', // 按元数据值的数字排序。
        'order' => 'DESC', // 降序排列,浏览数最多的文章在前。
        '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(); ?>

    以上方式需要浏览量统计插件或自定义浏览量统计后才会生效,可以使用WP_Query类来查询指定分类下的热门文章。