WordPressの「WP-PostViews」プラグインで閲覧数(view数)に応じてランキング表示する方法

WordPressの「WP-PostViews」プラグインで閲覧数(view数)に応じてランキング表示する方法

 

<?php
  $rankings = array(
    'post_type' => 'post',
    'posts_per_page' => 9,
    'meta_key' => 'views',
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
  );
  $ranking_post = get_posts($rankings);
  foreach($ranking_post as $post):
   setup_postdata($post); ?>
  <li>
    <div>
      <a href="<?php the_permalink(); ?>" class="flex">
        <p class="txt"><?php the_title(); ?></p>
      </a>
    </div>
  </li>
<?php endforeach; wp_reset_postdata(); ?>

 

ビュー数を表示するにはこちらのコード

<?php echo post_custom('views'); ?> Views

 

参考サイト
http://tcd-manual.net/?p=1145

category cloud