日: 2009年2月19日

J. BTON ‘s Recent Posts mu-plugin for WordPress MU

[JAPANESE]

Download the code , and FTP-upload the file to /wp-ontent/mu-plugin/. It will work as soon as file uploaded.

**FEATURE**

Parameter explanations
$how_many: how many recent posts are being displayed
$how_long: time frame to choose recent posts from (in days)
$cate: category ID to be selected
$limit: how many posts should be displayed from each category
$titleOnly: true (only title of post is displayed) OR false (title of post and name of blog are displayed)
$begin_wrap: customise the start html code to adapt to different themes
$end_wrap: customise the end html code to adapt to different themes

Sample call: bton_recent_posts(8, 30, 5, 2, true, ‘<li>’, ‘</li>’); >> total 8 most recent entries over the past 30 days, from cateID 5, 2 entries from each blog, displaying titles only
write code in template
ex. <ul><?php bton_recent_posts(8, 30, 5, 2, true, ‘<li class=”pageposts_list”>’, ‘</li>’); ?></ul>
And you can also add style in your css files like this.
li.pageposts_list {list-mark-style:none;}
span.pageposts_cont{font-size:small; color:#333;}
span.pageposts_date {font-size:x-small; color:#ccc;}
span.pageposts_blog {font-size:x-small; color:#ccc;}

->>[DOWNLOAD](bton_recent_posts_1.0.zip:2KB)

/*Now, Ver.2 available*/

WORDPRESS MUで、各ブログの新着エントリーをカテゴリーごとに数件ずつ表示するMUプラグイン

[ENGLISH ]

WORDPRESS MUで、マルチブログの各ブログについて(同じMU・DBで運用しているブログについて)、

  • 各サブブログから、
  • 指定したカテゴリーに属するエントリーで、
  • 公開されており、かつ、
  • エントリーの種類が「投稿=post」
  • エントリー後▲日以内の記事を
  • それぞれ○○件、最大●●件

抽出して、表示させるMU-プラグイン。

【概要】

サブブログ内のスパム・削除フラグなどが掛かっていない公開エントリーをメインブログのトップページなどに指定数だけ表示させる。

例えば、各サブブログにそれぞれNEWSカテゴリーがあり、NEWSカテゴリーの投稿を、サブブログごとに3件、3つのブログから合計9件、メインブログのトップページに表示させたい、といったときに使用する。

エントリーの抽出はカテゴリー単位で行うので、ブロック単位で、ニュースから2件ずつ、テーマから2件ずつ、という指定が可能。

bton_recent_posts()内のそれぞれの変数が表示の指定パラメータとなっている。

 bton_recent_posts($how_many, $how_long, $cate, $limit, $titleOnly, $begin_wrap, $end_wrap)

  1. $how_many: 全体でいくつのエントリーを表示させるか
  2. $how_long: ▲日以内の投稿
  3. $cate: 抽出するカテゴリーのID
  4. $limit: 各ブログから抽出するそれぞれのエントリーの数
  5. $titleOnly: trueならタイトル、投稿日、出典ブログ名、内容の一部抜粋なども表示する /falseなら、タイトルとエントリーへのリンクのみ表示
  6. $begin_wrap: リストを挟むHTMLタグ(開始タグ)
  7. $end_wrap: リストを挟むHTMLタグ(終了タグ)

表示の指定は、表示させたいテンプレート内(例えば、page.phpやindex.phpなど)で

<ul><?php bton_recent_posts(8, 30, 5, 2, true, ‘<li class=”pageposts_list”>’, ‘</li>’); ?></ul>

というように記述する。
この例では、全体で8つのエントリー、30日以内に投稿されたもので、かつ、カテゴリーIDが5のものを各2件、エントリーのタイトルだけではなく、出典ブログ名や投稿日時、投稿内容の一部も、<ul><li class=”pageposts_list”></li></ul>タグを使って表示させる、という指定になる。

複数のカテゴリーを表示するときは、下記のようにカテゴリーIDを変えて、コードを呼び出せば、別のブロック位置であってもそれぞれエントリーが表示されるので、ポータル的な表示が可能。プラグインのカスタマイズで、色々とバリエーションが作れる。

<ul><?php bton_recent_posts(8, 30, 5, 2, true, ‘<li class=”pageposts_list”>’, ‘</li>’); ?></ul>
<ul><?php bton_recent_posts(8, 30, 1, 2, true, ‘<li class=”pageposts_list”>’, ‘</li>’); ?></ul>

【使い方ソースをダウンロードし、FTPで、/wp_content/mu-plugin/ディレクトリにアップロード。(※mu-pluginディレクトリのプラグインは、管理画面のプラグインメニューで使用設定をしなくても、アップロードするだけで反映される。)

->>[ソースのダウンロード](bton_recent_posts_1.0.zip:2KB)

動作確認は一応していますが、ノーサポートです。もしものトラブル責任も負いません。ご自身のリスクの範囲内で自己責任で使用してください。

*コメント*0221/次のバージョンとの整合性を取るため、ちょっと変数名を変更しました。動作には変更ありません。 VER.2をリリースしました。