ページのカテゴリーわけ?
-
親ページを作成することが可能なら属性で親を指定して階層を作ってみてはいかがでしょう。
shokun0803さん
レスありがとうございます。
親ページを作りその下にジャンル別に子ページを作りました。
親ページ用のテンプレートを作り、下記コードを記載してみました。<?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?>
これだと親ページが複数ある場合に関係なく表示されるので困ってます^^;
たとえば親ページがpageID?が1000だけの子ページリストを表示させることは可能なのでしょうか?
Flexi Pages Widgetはどうでしょう?
torisanさん
すみません。めっちゃ大事なこと書き忘れてました^^;
ページが151ページあるのでできればジャンル毎にページで表示できないかと
考えてます^^;(ほんますみません(汁現状・・・
親ページ(ジャンルA)をつくりその親を指定した子供が71と
親ページ(ジャンルB)をつくりその親を指定した子供が30と
親ページ(ジャンルC)をつくりその親を指定した子供が50あります。そしてそれらのジャンル毎にページをつくり子供一覧を表示できないかと模索してます。
何かいい方法はありますでしょうか?うっ、すいません紹介したプラグインそのままでは出来ないかもしれませんね(汗
自分は改造して使っていたことをまじ忘れていました(汗Flexi Pages Widgetで改造した関数をそのまま載せます。($options[‘depth’] == -3の動作は修正していません。。。)
でテンプレートで以下のようにすると、初めからID25のページの子ページが展開された状態で表示されます。ID25に属する子ページしか表示されません。
子をクリックするとさらに子が展開されて表示されるので希望の動作と違うかもしれませんが。。。
flexipages(‘home_link=&title_li=&extract=25&child_of=25’);
function flexipages($options = ”)
{
$key_value = explode(‘&’, $options);
$options = array();
foreach($key_value as $value) {
$x = explode(‘=’, $value);
$options[$x[0]] = $x[1]; // $options[‘key’] = ‘value’;
}if($options[‘exclude’])
$exclude = explode(‘,’,$options[‘exclude’]);
else
$exclude = array();/* tirisan追加 START */
if($options[‘extract’])
$extract = explode(‘,’,$options[‘extract’]);
else
$extract = array();
/* tirisan追加 END */if( $options[‘depth’] == -2 || !isset($options[‘depth’])) { // display subpages only in related pages
/* tirisan修正 START */
$exflg = false;
$hierarchy = flexipages_currpage_hierarchy();
foreach ($exclude as $ex) {
if ( in_array ($ex, $hierarchy) ) {
$exflg = true;
}
}$subpages = flexipages_get_subpages();
foreach ($subpages as $subpage) { //loop through the sub pages
// if the parent of any of the subpage is not in our hierarchy,
// add it to the exclusion list
if ($exflg) {
$exclude[] = $subpage[‘ID’];
} else if ( !in_array ($subpage[‘post_parent’],$extract)) {
if ( !in_array ($subpage[‘post_parent’], $hierarchy) ) {
$exclude[] = $subpage[‘ID’];
}
}
}
$options[‘depth’] = 0;
/* tirisan修正 END */
} else if( $options[‘depth’] == -3 ) { // display subpages only in related pages
// depth = -3 gets rid of parents’ siblings$hierarchy = flexipages_currpage_hierarchy();
$subpages = flexipages_get_subpages();foreach ($subpages as $subpage) { //loop through the sub pages
if (
( $subpage[‘post_parent’] != $hierarchy[0] ) &&
( $subpage[‘post_parent’] != $hierarchy[1] ) &&
( !in_array ($subpage[‘ID’], $hierarchy) )
) {
$exclude[] = $subpage[‘ID’];
}
}
$options[‘depth’] = 0;
}if($options[‘include’]) {
$include = explode(‘,’, $options[‘include’]);
$page_ids = flexipages_pageids();
foreach($page_ids as $page_id) {
if(!in_array($page_id, $include) && !in_array($page_id, $exclude))
$exclude[] = $page_id;
}
$options[‘include’] = ”;
}if($exclude)
$options[‘exclude’] = implode(‘,’, $exclude);if($options[‘title_li’]) {
$title_li = $options[‘title_li’];
$options[‘title_li’] = “”;
}if($options[‘home_link’]) {
$display .=”<li class=\”page_item”;
if(is_home()) $display .= ” current_page_item”;
$display .= “\”>“.$options[‘home_link’].”“;
}foreach($options as $key => $value) {
if($key == ‘home_link’ || $key == ‘echo’)
continue;
if($opts) $opts .= ‘&’;
$opts .= $key.’=’.$value;
}$display .= wp_list_pages(‘echo=0&’.$opts);
if($title_li && $display)
$display = “<li class=\”pagenav\”>”.$title_li.”- \n”.$display.”
“;
if(isset($options[‘echo’]) && $options[‘echo’] == 0)
return $display;
else
echo $display;
}必要なコードを切り貼りして、新しいプラグイン、もしくはテーマ関数にすると良いかもしれません。
注意点としてこのコードのままだと警告が出ることも追加しておきます。長いコードを掲載してすいません(汗
- トピック「ページのカテゴリーわけ?」には新たに返信することはできません。