Determine page content based on page parent

How can I display a gallery shortcode for pages who are children of the page with an ID of 9, and the regular content for pages who aren’t? This is what I’ve tried so far, but it’s not working:

<?php global $wp_query; if( (9 == $ $wp_query->post->post_parent ) :?>
    <?php echo do_shortcode(''); ?>
<?php else (); ?>
    <?php the_content(); ?>

Related posts

Leave a Reply

2 comments

  1. $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()

  2. <?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(); ?>