[2006/09/22] WordPress:Customizable Post Listings
WordPress プラグイン。最新の投稿記事に日付を付けたり、本文テキストの冒頭を抜粋して表示させたり出来ます。
配布元:Plugin: Customizable Post Listings (Ver.1.1) by Scott Reillyさん
参考:WP plugin: 最近の投稿リストを表示 - Customizable Post Listings by ぼのさん
\wp-content\plugins\ 直下にアップロード後、管理画面のプラグインページでActive(有効化)にし、4種類の関数にパラメータと出力フォーマットを組み合わせるだけで色々な記事リストの表現が可能になります。
4種類の関数(Functions)
function c2c_get_recent_posts ($num_posts = 5,
$format = "<li>%post_date%: %post_URL%</li>",
$categories = '', $orderby = 'date',
$order = 'DESC',
$offset = 0,
$date_format = 'm/d/Y',
$authors = '',
$include_passworded_posts = false)
function c2c_get_random_posts($num_posts = 5,
$format = "<li>%post_date%: %post_URL%</li>",
$categories = '', $order = 'DESC',
$offset = 0,
$date_format = 'm/d/Y',
$authors = '',
$include_passworded_posts = false)
function c2c_get_recently_commented ($num_posts = 5,
$format = "<li>%comments_URL%<br />%last_comment_date%<br />%comments_fancy%</li>",
$categories = '',
$order = 'DESC',
$offset = 0,
$date_format = 'm/d/Y h:i a',
$authors = '',
$include_passworded_posts = false)
function c2c_get_recently_modified ($num_posts = 5,
$format = "<li>%post_URL%<br />Updated: %post_modified%</li>",
$categories = '',
$order = 'DESC',
$offset = 0,
$date_format = 'm/d/Y',
$authors = '',
$include_passworded_posts = false)
パラメータの説明
$num_posts : リストに表示させる件数/デフォルトで5件。
$format : 一件ごとの表示テンプレートになる記述(Format?)。percent substitution tags と HTMLのタグを組み合わせて定義出来る。"(ダブルクォーテーション)で囲んで記述する。
$categories : 表示するカテゴリのIDを指定。空欄のままだと全カテゴリーを表示。
$order : リストの並び順を指定。'ASC'=昇順、'DESC'=降順。デフォルトは 'DESC'
$offset : 表示を飛ばす件数。デフォルトは 0。
$date_format : 日付のフォーマット。phpに準拠。西暦.月.日で表示させたいなら'Y.n.j'
$authors : 表示する投稿者(Author)のIDを指定。複数名の場合は半角スペースで区切るとOR条件で出力。空欄で全投稿者が対象。省略可。
$include_passworded_posts : パスワードで閲覧制限のかかっている記事をリストに含めるかどうか。'true' or 'false'で指定。省略可。
表示テンプレートに使える percent substitution tags とその説明
%comments_count% // 記事へのコメント数
%comments_fancy% // ??未テストでよくわかりません>< 配布元Notes参照して下さい。
%comments_url% // 記事のコメント部先頭へのURL
%comments_URL% // 同上リンク付き記事タイトル
%last_comment_date% // 記事への最新コメント日付
%last_comment_id% // 記事への最新コメントのID
%last_comment_URLurl% // 記事への最新コメントのURL
%last_commenter% // 記事への最新コメント投稿者名
%last_commenter_URL% // リンク付き記事への最新コメント投稿者名(コメント投稿者のURLが入力されているとき
%post_author% // 記事の著者名
%post_author_count% // 著者の投稿件数
%post_author_posts% // 著者記事アーカイブへのリンク付き著者名
%post_author_url% // URL($authordata->user_url)リンク付き著者名
%post_content% // 記事コンテンツ全文
%post_date% // 記事の投稿日
%post_excerpt% // 記事抜粋
%post_excerpt_short% // 独自の短い記事抜粋(サイドバー向き)
%post_id% // 記事ID
%post_modified% // 記事の最終更新日
%post_title% // 記事タイトル
%post_url% // 記事のパーマリンクURL
%post_URL% // パーマリンク付き記事タイトル
コード記述サンプル
最新5件の記事を、日付(西暦.月.日):パーマリンク付き記事タイトル+改行して本文冒頭のn文字(後で説明/備忘録:カスタマイズした点)を降順で表示。(全ての投稿者の記事を表示/パスワード制限のページは表示しない:この2点は記述を省略)
<?php if (function_exists('c2c_get_recent_posts')) { ?>
<ul> <?php c2c_get_recent_posts() ?> </ul>
備忘録:カスタマイズした点
記事本文から冒頭250文字(全角では125文字)までをリストに表示させるには
customizable-post-listings.php 146-151行目参照。下のソースはデフォルト。
//-- Some things you might want to configure -----
$excerpt_words = 6; // Number of words to use for %post_excerpt_short%
$excerpt_length = 50; // Number of characters to use for %post_excerpt_short%, only used if $excerpt_words is 0
$idmode = ‘nickname’; // how to present post author name
$comment_fancy = array(’No comments’, ‘1 Comment’, ‘%comments_count% Comments’);
//-- END configuration section -----
%post_excerpt_short%で文字数を指定できるのは、$excerpt_wordsの値を0にしている時だけ。とのことで、表示させる本文を冒頭から250字までと制限するために、以下の通り変更。
//-- Some things you might want to configure -----
$excerpt_words = 0; // Number of words to use for %post_excerpt_short%
$excerpt_length = 250; // Number of characters to use for %post_excerpt_short%, only used if $excerpt_words is 0
$idmode = ‘nickname’; // how to present post author name
$comment_fancy = array(’No comments’, ‘1 Comment’, ‘%comments_count% Comments’);
//-- END configuration section -----