Blogで記事を書いていると、これは読んで貰いたいなーとか思う事があるかもしれません。
そんな時の誘導性と管理性を高く備えているカスタマイズです。
ここでは、そんな感じの任意のエントリーを指定して表示させる方法をプラグインを利用して試してみました。
プラグインのDL
[配布元]mt-favorite-entries プラグインで「よりぬき NDO::Weblog」 : NDO::Weblog
上記よりコードをコピーして、 mt-favorite-entries.pl として保存します。
# $Id: mt-favorite-entries.pl,v 1.8 2004/08/20 19:51:44 naoya Exp $
package MT::Plugin::FavoriteEntries;
use strict;
use warnings;
use MT::Template::Context;
our $VERSION = 0.01;
## for Movable Type 3.0
if (MT->can('add_plugin')) {
require MT::Plugin;
my $plugin = MT::Plugin->new;
$plugin->name("Favorite Entries Plugin " . $VERSION);
$plugin->description("You can choice your favorite entries and show them.");
MT->add_plugin($plugin);
}
MT::Template::Context->add_container_tag(FavoriteEntries => \&favorite_entries);
sub favorite_entries {
my ($ctx, $args) = @_;
my $content = '';
my $builder = $ctx->stash('builder');
my $tokens = $ctx->stash('tokens');
my @entries_id = map { s/\s+//g; $_ } split(/,/, $args->{favorite_entries});
for my $e (map { MT::Entry->load($_) } @entries_id) {
my $saved_entry = $ctx->stash('entry'); # Hack
$ctx->stash('entry', $e);
local $ctx->{current_timestamp} = $e->created_on;
local $ctx->{modification_timestamp} = $e->modified_on;
defined(my $out = $builder->build($ctx, $tokens))
or return $ctx->error($builder->errstr);
$content .= $out;
$ctx->stash('entry', $saved_entry);
}
$content;
}
1;
プラグインのUL
MTルートディレクトリ/plugins の中にアップします。
テンプレートに記述
下記コードを表示させたい箇所に記述します。
<MTFavoriteEntries favorite_entries="1,2,3">
<a href="<$MTEntryPermalink>" title="<$MTEntryDate language="en" format="%a, %m %d, %Y %H:%M"$>"><$MTEntryTitle$></a><br />
</MTFavoriteEntries>
表示させるエントリーには エントリーID を用います。
関連記事
当サイトではサイト内エントリーランキングページに表示させてます。(09月02日)
参考記事
■mt-favorite-entries プラグインで「よりぬき NDO::Weblog」 : NDO::Weblog
2006/10/20 02:46:44:記事書き直し
2007/01/31 22:55:03:記事書き直し