TatterTools 在sidebar中顯示人氣文章

原本的構想是直接在列表頁面中直接使用 依時間排序/依人氣排序 的方式下去作修改。
但受限於所學有限,怕改了出來卻變成個龐大垃圾,於是只好作罷。
改為在sidebar中作列表顯示的方式,先暫時用這方法頂替。

同樣這一篇也是屬於顯示單篇閱讀次數的延伸,必須先做完顯示單篇閱讀次數的修改之後才可以依照本篇的步驟作修改。

您可以到這兩個地方找到 顯示單篇閱讀次數 修改方法:

關於修改後的效果您可以參見本站左側導覽列中的人氣文章,修改步驟如下:


1.開啟 skin.html,在適當的地方加入:

html · [高亮] · [原始]

  1. <h1>人氣文章</h1>
  2. <s_htps_rep>
  3.     <li>[##_htps_rep_view_cnt_##]
  4.     <a href="[##_htps_rep_link_##]">[##_htps_rep_title_##]</a></li>
  5. </s_htps_rep>
  6. </ul></div>
<h1>人氣文章</h1>
<div><ul>
<s_htps_rep>
    <li>[##_htps_rep_view_cnt_##]
    <a href="[##_htps_rep_link_##]">[##_htps_rep_title_##]</a></li>
</s_htps_rep>
</ul></div>

2.開啟 inc_presswork.php,搜尋:

php · [高亮] · [原始]

  1. $p_rep = str_replace("[##_rctps_rep_link_##]", "index.php?pl=$no", $p_rep);
  2.             $p_rep = str_replace("[##_rctps_rep_title_##]", str_cut($title, $p_rct_ps_trunc, 1), $p_rep);
  3.             $p_rep = str_replace("[##_rctps_rep_rp_cnt_##]", $rp_cnt, $p_rep);
  4.             $p .= $p_rep;
  5.         }
  6.         return $p;
  7.     }
$p_rep = str_replace("[##_rctps_rep_link_##]", "index.php?pl=$no", $p_rep);
            $p_rep = str_replace("[##_rctps_rep_title_##]", str_cut($title, $p_rct_ps_trunc, 1), $p_rep);
            $p_rep = str_replace("[##_rctps_rep_rp_cnt_##]", $rp_cnt, $p_rep);
            $p .= $p_rep;
        }
        return $p;
    }

後面加入:

php · [高亮] · [原始]

  1. function get_hot_rep(){
  2.         global $db, $dbid, $is_public;
  3.         unset($p);
  4.  
  5.         $p_rct_ht_cnt = 5;     // 顯示人氣文章筆數,可自行更改
  6.         $p_rct_ht_trunc = 18// 人氣文章標題顯示字數,可自行更改
  7.  
  8.         $sql = "select no, title, view_cnt from t3_".$dbid." where $is_public order by view_cnt desc limit 0, $p_rct_ht_cnt";
  9.         // print $sql;
  10.         $result = @mysql_query($sql);
  11.         while(list($no, $title, $view_cnt) = @mysql_fetch_array($result)) {
  12.             if ($view_cnt) $view_cnt = "Hit: $view_cnt"; else $rp_cnt = "Hit: 0";
  13.             $p_rep = $GLOBALS["skin"]->s_htps_rep;
  14.             $p_rep = str_replace("[##_htps_rep_link_##]", "index.php?pl=$no", $p_rep);
  15.             $p_rep = str_replace("[##_htps_rep_title_##]", str_cut($title, $p_rct_ht_trunc, 1), $p_rep);
  16.             $p_rep = str_replace("[##_htps_rep_view_cnt_##]", $view_cnt, $p_rep);
  17.             $p .= $p_rep;
  18.         }
  19.         return $p;
  20.     }
function get_hot_rep(){
        global $db, $dbid, $is_public;
        unset($p);

        $p_rct_ht_cnt = 5;     // 顯示人氣文章筆數,可自行更改
        $p_rct_ht_trunc = 18;  // 人氣文章標題顯示字數,可自行更改

        $sql = "select no, title, view_cnt from t3_".$dbid." where $is_public order by view_cnt desc limit 0, $p_rct_ht_cnt";
        // print $sql;
        $result = @mysql_query($sql);
        while(list($no, $title, $view_cnt) = @mysql_fetch_array($result)) {
            if ($view_cnt) $view_cnt = "Hit: $view_cnt"; else $rp_cnt = "Hit: 0";
            $p_rep = $GLOBALS["skin"]->s_htps_rep;
            $p_rep = str_replace("[##_htps_rep_link_##]", "index.php?pl=$no", $p_rep);
            $p_rep = str_replace("[##_htps_rep_title_##]", str_cut($title, $p_rct_ht_trunc, 1), $p_rep);
            $p_rep = str_replace("[##_htps_rep_view_cnt_##]", $view_cnt, $p_rep);
            $p .= $p_rep;
        }
        return $p;
    }

3.開啟 inc_function.php,搜尋:

php · [高亮] · [原始]

  1. list($sval, $this->s_link_rep) = cut_skintag($sval, "s_link_rep");
list($sval, $this->s_link_rep) = cut_skintag($sval, "s_link_rep");

後面加入:

php · [高亮] · [原始]

  1. list($sval, $this->s_htps_rep) = cut_skintag($sval, "s_htps_rep");
list($sval, $this->s_htps_rep) = cut_skintag($sval, "s_htps_rep");

4.開啟 index.php,搜尋:

php · [高亮] · [原始]

  1. if (strpos($d1, "[##_s_link_rep_##]")) $d1 = str_replace("[##_s_link_rep_##]", get_link_rep(), $d1);
if (strpos($d1, "[##_s_link_rep_##]")) $d1 = str_replace("[##_s_link_rep_##]", get_link_rep(), $d1);

後面加入:

php · [高亮] · [原始]

  1. if (strpos($d1, "[##_s_htps_rep_##]")) $d1 = str_replace("[##_s_htps_rep_##]", get_hot_rep(), $d1);
if (strpos($d1, "[##_s_htps_rep_##]")) $d1 = str_replace("[##_s_htps_rep_##]", get_hot_rep(), $d1);

7 Responses to “TatterTools 在sidebar中顯示人氣文章”

  1. DearJohn Says:

    感謝感謝!
    我也試成功了…
    這是我夢寐以求的功能啊!

  2. Beata Says:

    其實這也是我自己比較需要的功能
    既然做出來了
    索性分享給大家
    同樂同樂咩!

  3. helenna Says:

    請問
    我的是MT(Movable Type)系統
    也適用嗎?

  4. Beata Says:

    不適用…
    因為資料庫中文章存放的位置完全不同

  5. 南庄 Says:

    很想把我自己寫和蒐集的程式碼
    1000多條用wordpress做出來

    看來我來對地方了

  6. Beata Says:

    哈~
    好期待閣下的WordPress呀!
    製造出來別忘了提醒Beata去觀摩觀摩唷!

  7. texas holdem p oker tin Says:

    texas holdem p oker tin…

    subscriber reluctance hammering familiarization paradigm accredit …

Leave a Comment