i'm query child pages of a page ID. How can i echo the parent page where it says "PARENT TITLE ? Using <?php echo get_the_title( $ID ); ?>
is not an option.
<?php
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => '2', //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order'
);
$childrens = new WP_Query( $args );
if ( $childrens->have_posts() ) : ?>
<div class="content">
<h2 class="big grid_3">PARENT TITLE</h2>
<div class="grid_6 right">
<?php while ( $childrens->have_posts() ) : $childrens->the_post(); ?>
<div class="grid_2 left" id="teaser" >
<p class="subtitle"></p>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a class="cta_light" href="<?php the_permalink(); ?>">Mehr erfahren</a>
</div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
Thanks!
i'm query child pages of a page ID. How can i echo the parent page where it says "PARENT TITLE ? Using <?php echo get_the_title( $ID ); ?>
is not an option.
<?php
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => '2', //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order'
);
$childrens = new WP_Query( $args );
if ( $childrens->have_posts() ) : ?>
<div class="content">
<h2 class="big grid_3">PARENT TITLE</h2>
<div class="grid_6 right">
<?php while ( $childrens->have_posts() ) : $childrens->the_post(); ?>
<div class="grid_2 left" id="teaser" >
<p class="subtitle"></p>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a class="cta_light" href="<?php the_permalink(); ?>">Mehr erfahren</a>
</div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
Thanks!
Share Improve this question edited Jan 31, 2019 at 21:18 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 31, 2019 at 20:47 baalstormbaalstorm 211 bronze badge 1- Why isn’t it an option? – Krzysiek Dróżdż Commented Jan 31, 2019 at 20:51
1 Answer
Reset to default 2I'm not entirely sure if I get your problem correctly, because of the "it's not an option part", but...
You get children pages of page with ID = 2, so it looks like you want to display the title of that page. If so, then this code will solve your problem:
<?php
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => '2', //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order'
);
$childrens = new WP_Query( $args );
if ( $childrens->have_posts() ) :
?>
<div class="content">
<h2 class="big grid_3"><?php echo get_the_title(2); ?></h2>
<div class="grid_6 right">
<?php while ( $childrens->have_posts() ) : $childrens->the_post(); ?>
<div class="grid_2 left" id="teaser" >
<p class="subtitle"></p>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a class="cta_light" href="<?php the_permalink(); ?>">Mehr erfahren</a>
</div>
<?php endwhile; // <- I had to move that, it was in wrong place so you were closing more divs than you were opening in that loop ?>
</div>
</div><!-- .content -->
<?php
endif;
// wp_reset_query(); <- there is no point in resetting query - you haven't changed it
wp_reset_postdata(); // on the other hand you should reset postdata
?>
PS. Also take a look at my comments - I had to make some changes in your code, because it was generating incorrect HTML output.