[WP plugin] Sideblog 與 Show Categories

zonbleAside 這篇文章中提到快速製作 Sideblog 的方法,而 dotann 也提供一個好用的 plugin: Show Categories 1.4。綜合上面兩者,我完成了右邊的 Links 項目,以下為實作筆記:

1.
編輯 wp-config.php,加入一行 $cat_aside = 分類ID;
例如我要將 id 為 1 的分類作為 Sideblog,則

$cat_aside = 1;

2-a.
由於我不希望 Sideblog 的文章內容出現在首頁裡,所以編輯 wp-blog-header.php,尋找

// Author/user stuff

在其上一行加入

if($cat == 0 && $category_name == '' && !$p && !isset($user_ID) && !$s && !$year){
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";
$whichcat .= " AND";
$whichcat .= " (category_id != $cat_aside)";
}

2-b.
如果要讓 Sideblog 的文章直接出現在首頁中,則依照 zonble 的作法

3. 再來,利用 Show Categories 這個 plugin (download)

3-1.
將 showcategories.php 放至你的 plugins 資料夾,以及在後台啟用它

3-2.
編輯 index.php,在 <div id="menu"> 此一標籤內,選擇你想加入的地方,加入:

<li><?php echo show_category_posts('category=9&&scp_title=Links&scp_limit=3&scp_status=publish&sort_order=DESC&sort_field=post_name'); ?></li>
<ul>
<?php if ($scp_posts) : foreach ($scp_posts as $post) : start_wp(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a>&nbsp;<?php echo $post->post_excerpt ?> <br />
<span class="sidecomments">
<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments ()')); ?></span></li>
<?php endforeach; ?>
<?php else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
</ul>

第一行中 show_category_posts() 內參數的用法,請見壓縮檔中的/DOCS/html/index.html

其中主要的幾個參數: category=分類id&scp_title=標題&scp_limit=顯示文章數

完成圖:
copyright reserved by hsuyo

如果不要迴響留言部分,則將

<span class="sidecomments">
<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments ()')); ?></span>

刪去

3-3.
隱藏分類中的項目,修改 index.php 中的 <?php wp_list_cats(); ?>,加入 exclude=分類id, ex:

<?php wp_list_cats('sort_column=name&optioncount=1&exclude=1'); ?>

如此,id 為 1 的分類即不會出現在 menu 的分類項目中

Bookmark to del.icio.usBookmark to furlBookmark to Blinklist

5 Responses to “[WP plugin] Sideblog 與 Show Categories”


  1. 多谢,只是< ?php endforeach; ?>后面的应该去掉

  2. PHP endforeach;” 后面的”/ul”应该去掉

  3. 謝謝你的提醒,已修改!

  4. 如果要用在WP1.5呢?
    我剛剛找到這個網址http://randomlog.net/archives/2005/01/28/implementing-matts-asides-with-wp-15/
    也照裡面的做了,可是很像都不成功。
    不知道hsuyo有沒有方法呢?

  5. 恩恩..給我一點時間研究看看吧~
    因為這兩天是週末 XD