以下のコードAとコードBを試している最中、不思議な事に両方とも記述するとコードBが思い通りに動き、コードAを外すとコードBが思い通りに動きません。
コードA
<?php
if ( is_single() ) :
$categories = get_the_category( $post->ID );
// カテゴリー ID 順に並べ替える場合は下の行をアンコメント
// if ( !empty( $categories ) ) usort( $categories, '_usort_terms_by_ID' );
foreach ( $categories as $cnt => $cat ) :
?>
<div id="toggler-<?php echo $cnt+1; ?>" class="closed" title="<?php echo esc_attr( $cat->name ); ?> の投稿一覧">
<div>
<ul>
<?php
$single_posts = get_posts( "numberposts=-1&category=$cat->term_ID&order=asc" );
foreach ( $single_posts as $post ) :
?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php
endforeach; // single_posts
?>
</ul>
</div>
</div>
<?php
endforeach; // categories
endif; // is_single
?>
コードB
<?php if (is_single()) : ?>
<ul>
<?php
$cat = get_the_category(); $cat = $cat[0];
//子孫が要る時
remove_filter( 'pre_option_category_children', 'my_category_children' );
//子孫が要らない時
//add_filter( 'pre_option_category_children', 'my_category_children' );
//
$myposts = get_posts('category='. $cat->cat_ID);
//$myposts = get_posts('category='. $cat->category_parent);
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
ここで言う思い通りの動きとは、単一記事表示中は同一カテゴリーの投稿一覧をサイドバーに表示させたいという事ですが、どうしてコードAを外すとコードBが機能しなくなるのでしょうか。
どなたかご教授頂けないでしょうか。
尚、コードBの子孫が要る時と要らない時は、自作テーマのfunctions.phpに以下のコードを記述(フォーラムから引用)しています。
function my_category_children( $return ) {
return array();
}
add_filter( 'pre_option_category_children', 'my_category_children' );
宜しくお願い致します。