ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文

  メンテナンス 前画面に戻る

対象スレッド 件名: WordPress の改造
名前: lightbox
処理選択
パスワード

件名 WordPress の改造
名前 lightbox
コメント
@DIV
WordPress は、「ページ」という概念があるので、時系列な投稿データでしか管理できない
一般的な CMS と違って「情報」を管理できます。

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

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

この処理は、classes.php 内の class Walker_Page extends Walker で行います
@END

@C:red(post-template.php に、wp_list_pages という関数があって呼ばれるようです。
ここから、walk_page_tree 関数へ飛んで、Walker_Page オブジェクトが作成されます。)

@DIV
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";
	}

}
@END


↓実装サンプル
http://winofsql.sakura.ne.jp/wordpress/