如何为ID为9的页面的子页面显示库快捷码,为ID为9的页面显示常规内容?这是我迄今为止尝试过的,但不起作用:
<?php global $wp_query; if( (9 == $ $wp_query->post->post_parent ) :?>
<?php echo do_shortcode(\'[gallery link="file" columns="1" size="large"]\'); ?>
<?php else (); ?>
<?php the_content(); ?>
最合适的回答,由SO网友:pcarvalho 整理而成
$thispageid = get_the_ID();
$thispageparent = get_ancestors($thispageid);
if( in_array( 9, $thispageparent ) )
echo do_shortcode(\'[gallery link="file" columns="1" size="large"]\');
else
the_content();
reference get_ancestors()