admin管理员组文章数量:1297088
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
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
1 Answer
Reset to default 0Use WP_Query
class to do it:
$the_query = new WP_Query( array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => 1,
) );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2 class="subpagetitle">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php endwhile;
// Reset Post Data
wp_reset_postdata();
本文标签: Show page title just from the first childpage in template
版权声明:本文标题:Show page title just from the first child-page in template 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741649065a2390363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论