Show page title just from the first child-page in template
Question
how can I do this:
Pages:
Home
– sub-1
— sub-sub-1
— sub-sub-sub-1
On home-page should only show the page-title of the first child-page like:
sub-1
I found this:
<?php $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<h2 class="subpagetitle"><a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a></h2>
<?php endforeach; endif; ?>
But it doesn´t work for me at all. The title will be show two times and show all child-page titles (sub-1, sub-sub-1, sub-sub-sub-1)
Thanks
Ogni
0
code, templates, title
4 years
2020-02-24T08:38:37-05:00
2020-02-24T08:38:37-05:00 0 Answers
76 views
0
Leave an answer