ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
WordPress の改造
日時: 2008/05/19 17:14
名前: lightbox



拡張子:
WordPress は、「ページ」という概念があるので、時系列な投稿データでしか管理できない
一般的な CMS と違って「情報」を管理できます。

ただ、ページの階層構造は入力できるのですが、
ツリーのように、子ノードを非表示にはできないようなので改造しました。

1) レベル 0 のページにリンクを作成しない
2) レベル 1 以上は、最上位レベルをクリックした時に表示
3) 最上位レベルを再度クリックすると非表示。

この処理は、classes.php 内の class Walker_Page extends Walker で行います
post-template.php に、wp_list_pages という関数があって呼ばれるようです。 ここから、walk_page_tree 関数へ飛んで、Walker_Page オブジェクトが作成されます。
拡張子:
class Walker_Page extends Walker {
	var $tree_type = 'page';
	var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
	
	# javaScrip で表示・非表示をコントロールする為の一意ID用
	var $counter = 0;
	var $counter_flg = false;

	function start_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);

		# UL に id をセット
		if ( $this->counter_flg ) {
			$output .= "\n$indent<ul style='display:none' id='tree{$this->counter}'>\n";
			$this->counter_flg = false;
		}
		else {
			$output .= "\n$indent<ul id='tree{$this->counter}'>\n";
		}
		$this->counter++;
	}

	function end_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul>\n";
	}

	function start_el(&$output, $page, $depth, $current_page, $args) {
		if ( $depth )
			$indent = str_repeat("\t", $depth);
		else
			$indent = '';

		extract($args, EXTR_SKIP);
		$css_class = 'page_item page-item-'.$page->ID;
		if ( !empty($current_page) ) {
			$_current_page = get_page( $current_page );
			if ( in_array($page->ID, (array) $_current_page->ancestors) )
				$css_class .= ' current_page_ancestor';
			if ( $page->ID == $current_page )
				$css_class .= ' current_page_item';
			elseif ( $_current_page && $page->ID == $_current_page->post_parent )
				$css_class .= ' current_page_parent';
		}

		$ttl = apply_filters('the_title', $page->post_title);
		# 最上位レベル
		if ( $depth == 0 ) {
			# 最上位レベルなので、ID を作成しておく( 最上位レベルのみ対応 )
			$this->counter++;
			$this->counter_flg = true;
			# クリックした時の処理を1行 JavaScript で記述
			$output .= $indent . '<li class="' . $css_class . "\" onClick='chkobj=document.getElementById(\"tree{$this->counter}\").style;if (chkobj.display==\"\") { chkobj.display=\"none\";} else { chkobj.display=\"\";}' style='cursor:pointer;color:navy;font-weight:bold'>" . apply_filters('the_title', $page->post_title) . "</li>";
		}
		# ここは通常
		else {
			$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
		}

		if ( !empty($show_date) ) {
			if ( 'modified' == $show_date )
				$time = $page->post_modified;
			else
				$time = $page->post_date;

			$output .= " " . mysql2date($date_format, $time);
		}
	}

	function end_el(&$output, $page, $depth) {
		$output .= "</li>\n";
	}

}
↓実装サンプル http://winofsql.sakura.ne.jp/wordpress/
メンテナンス

本文の再加工 ( No.1 )
日時: 2008/05/19 17:34
名前: lightbox


日時: 2008/05/19 17:34
名前: lightbox
拡張子:
これは、こうされる事を想定して作られていたようなコードでした。
本文に対する専用マクロはみなここで改造できます

wp-includes/post-template.php の the_content関数を変更しています。
SyntaxHighligter を埋め込むマクロを実装しています。 以下専用構文
拡張子:
@CODE(vb,vb_7_01.txt)
@CODE(php,php_7_02.txt)
@CODESET
※ @CODESET は、SyntaxHighligter の実行文の埋め込みです。 ※ オリジナルの説明では、.js をページの最後に書く必要があります。 ※ また、世間のサンプルではページのロードイベントを使用しているものがありますが、それでは正しく動かない場合もあります。 ※ 外部 js、css -> head、実行文 -> 最後のソースコード以降の任意の場所、が管理上理想的です。
拡張子:
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content', $content);
	$content = str_replace('>', '&gt;', $content);


	# **************************************************
	# ここから改造
	# 専用マクロを正規表現で検索して置き換え処理
	# ここでは、外部ファイルからソースコードを取り出して
	# SyntaxHighligter の構文に置き換え
	# **************************************************
	$matches = array();
	mb_ereg_search_init( $content, "@CODE\(([^\)]*),([^\)]*)\)", "i" );
	while( TRUE === mb_ereg_search() ) {
		$work = mb_ereg_search_getregs();
		$matches[] = $work;
	}

	foreach( $matches as $key => $value ) {
		$repl_file = file_get_contents( "codetext/" . $value[2] );
		$repl_file = str_replace('<', '&lt;', $repl_file);
		$repl_file = str_replace('>', '&gt;', $repl_file);

		$content = str_replace($value[0], "<pre name='code' class='{$value[1]}'>{$repl_file}</pre>", $content);
	}

	$content = str_replace(
		'@' . 'CODESET', 
		'<script type="text/javascript">dp.SyntaxHighlighter.ClipboardSwf = "/clipboard.swf"; dp.SyntaxHighlighter.HighlightAll("code");</script>',
		 $content);

	# **************************************************
	# ここまで改造
	# **************************************************

	echo $content;
}
↓実装サンプル http://winofsql.sakura.ne.jp/wordpress/?page_id=7
このアーティクルの参照用URLをクリップボードにコピー メンテナンス