中文 WordPress 工具箱的熱門文章

Wordpress

  我用的Wordpress外掛「中文 WordPress 工具箱」裡面有顯示「評論最多的帖子」這個功能,也就是我的網站右手邊的「熱門文章」區塊。但是他會包含頁面,如我的花履歷以及留言版,都是用獨立的頁面做成的,這樣一來留言版也會出現在熱門文章裡頭,非常的不合邏輯。另外最新文章這一區塊也有這個問題,再怎麼說「留言板」都不應該當成是文章啊!所以我動手修改了這個外掛。
第103行

$mostcommenteds = $wpdb->get_results("SELECT $tableposts.ID as ID, post_title, post_name, COUNT($tablecomments.comment_post_ID) AS 'comment_total' FROM $tableposts LEFT JOIN $tablecomments ON $tableposts.ID = $tablecomments.comment_post_ID WHERE comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' AND post_status = 'publish' AND post_password = '' GROUP BY $tablecomments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");

改成這樣:
$mostcommenteds = $wpdb->get_results("SELECT $tableposts.ID as ID, post_title, post_name, COUNT($tablecomments.comment_post_ID) AS 'comment_total' FROM $tableposts LEFT JOIN $tablecomments ON $tableposts.ID = $tablecomments.comment_post_ID WHERE comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' AND post_status = 'publish' AND post_type = 'post' AND post_password = '' GROUP BY $tablecomments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");

第174行
$request = "SELECT ID, post_title, post_date, post_content FROM $tableposts WHERE post_status = 'publish' ";

改成這樣:
$request = "SELECT ID, post_title, post_date, post_content FROM $tableposts WHERE post_status = 'publish' AND post_type = 'post' ";

  若你沒有修改其他任何地方,可以直接下載我的修改版,mulberrykit.php.txt,下載完後把檔名最後面的.txt刪掉,也就是說把 mulberrykit.php.txt改成mulberrykit.php,然後覆蓋到你的Plugins資料夾,就可以了。

回應

發表新回應

這個欄位的內容會保密,不會公開顯示。 If you have a Gravatar account, used to display your avatar.
  • 自動將網址與電子郵件位址轉變為連結。
  • 可使用的 HTML 標籤:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自動斷行和分段。

更多關於格式選項的資訊