我想在“about”页面及其子页面上显示一个特定的动态侧栏。From the codex, 我尝试了以下方法:
<?php
// Begin main loop
if ( have_posts() ): while ( have_posts() ):
the_post();
// If about page and about child pages
if ( is_page(\'about\') && $post->post_parent > 0 ) {
dynamic_sidebar(\'about\');
}
else {
dynamic_sidebar(\'general\');
}
// End loop
endwhile;
endif;
?>
这行不通。我错过了什么?
我也尝试了以下方法。这对祖父母和父母有效,但对孩子无效。
<?php
if (is_page (17) || (17 == $post->post_parent ) ) {
dynamic_sidebar(\'about\');
}
else {
dynamic_sidebar(\'general\');
}
?>
下面是一个子页面的post对象转储,使用
<?php echo \'<pre>\' . print_r( $post, true ); ?>
:
WP_Post Object
(
[ID] => 382
[post_author] => 1
[post_date] => 2018-08-15 17:02:56
[post_date_gmt] => 2018-08-15 16:02:56
[post_content] =>
[post_title] => Art
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => art
[to_ping] =>
[pinged] =>
[post_modified] => 2018-10-22 12:39:27
[post_modified_gmt] => 2018-10-22 11:39:27
[post_content_filtered] =>
[post_parent] => 378
[guid] => http://domain.local/?page_id=382
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)