以前、唯奈さんに Twitter でリクエストされてちょちょっと書いた WordPress 用プラグイン「Custom more text」。
投稿のカスタムフィールド「custom-more-text」にテキストが設定されていた場合、「続きを読む」のテキストを変更するプラグインです。
http://dl.dropbox.com/u/110305/custom-more-text.php
仕組みは簡単で、more-link の #more-xxxx を削除した時に使用した "the_content_more_link" フィルタをフックして、カスタムフィールド「custom-more-text」に設定されたテキストと置き換えてるだけです。
このプラグインを元にすれば、「続きを読む」のテキストをエントリの件名に置換したりも簡単にできると思うよ。
<?php
/*
Plugin Name: Custom more text
Plugin URI:
Description: 「続きを読む」のテキストをカスタムフィールド「custom-more-text」に設定されたテキストに置き換える。(WP2.8以降でないと動作しません)
Author: wokamoto
Version: 0.0.2
Author URI: http://dogmap.jp/
*/
function custom_more_text( $output ) {
$custom_more_text = get_post_meta(get_the_ID(), 'custom-more-text', true);
if ( !empty($custom_more_text) )
$output = preg_replace('/(<a [^>]*>)[^<]*(<\/a>)/i', '$1'.$custom_more_text.'$2', $output );
return $output;
}
add_filter( 'the_content_more_link', 'custom_more_text' );
?>
つぶやく
コメント