Posted by をかもと at 2010年1月6日 水曜日

以前、唯奈さんに 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' );
?>

コメント

  • コメントはまだありません。

コメントする


Twitter ID を入力すると新しいコメントがあった際、 @dogmap_jp が、あなた宛に@リプライでお知らせします。

入力いただいたメールアドレスから、TwitterGravatar に登録されているアイコンを表示します。
(メールアドレスは公開されません)

改行と段落タグは自動で挿入されます。メールアドレスは表示されません。

:mrgreen: :-P :-D :-) ;-) :-o :-| :-( 8-O :-? 8-) :twisted: :evil: :oops: :roll: :cry: :lol: :-x more »