低調の美國生活

各種疑難雜症

最多人瀏覽,顯示點閱數量的功能製作

現在有比較新的作法,我直接把code貼在內文。

<?php
    $args = array(
      'posts_per_page'  => -1,  /* get 4 posts, or set -1 for all */
      'orderby'      => 'meta_value_num',  /* this will look at the meta_key you set below */
      'meta_key'     => 'post_views_count',
      'order'        => 'DESC',
      'post_type' => 'post',
      //'post_type' => array('news','database'),
      'post_status'  => 'publish'
      );

      $myposts = new WP_Query( $args );
      if ($myposts->have_posts()) {
      while ($myposts->have_posts()) {
        $myposts->the_post(); ?>
        <div class="mb-1 small">
          <div class="p-1">
          <a href="<?php the_permalink() ?>" target='blank'>
            <span>
              <?php the_title(); ?>
              <small><span class="">
                <?php
                  echo 'x';
                  echo getPostViews(get_the_ID());
                  ?>
              </span></small>
            </span>
            <br>
            <span class="font-weight-lighter">
              <?php
              $content = get_the_excerpt();
              $trimmed_content = mb_substr($content, 0, 87);
              echo $trimmed_content;
              ?>
            </span>
          </a>
          </div>
        </div>


        <?php
      }
      }

     ?>


在網域選擇部分,除了Godaddy外,現在還有 NameCheap可供選擇,人如其名,這家的網域管理比 Godaddy還便宜,現在NameChaep一年的管理用費只要3.98美元起跳,很划算!可透個這個NameCheap連結申請網域


網路空間多半都會提供無限網路空間+內置一鍵安裝”Wordpress”的標配,像是Blue Host,而且因為競爭激烈,無限網路空間才每月才3.95美元起跳
Unlimited Web Hosting from Bluehost for only $3.95!

以此網站為例,我在以下己個地方加入了最多人瀏覽與計數功能:

所需要外掛: wp postview plus

將計數功能加在單篇文章或首頁的方法

以下以首頁為例:

找到index.php

將php代碼貼在此位置

顯示結果

將最多人瀏覽文章功能顯示在側邊欄(Sidebar)

  • 到 >外觀 >模組(widget) >增加文字模組Text) >將php代碼貼在以下位置:

參數說明:11, 17, 表示顯示11篇文章,每篇文章只顯示17字

  • 顯示如下


發佈於 1月27日2011年