Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

display child page rather than parent page WordPress

  • SOLVED

How can I have the parent page open to the first child page (in that parent)?

For example, on this site http://dianasimkin.com/

I would like when you click on Lamaze that
http://dianasimkin.com/?page_id=49
opens rather than http://dianasimkin.com/?page_id=5.

The same applies to http://dianasimkin.com/?page_id=20 appearing when you go to http://dianasimkin.com/?page_id=10.

I am building a child theme off thematic.

Answers (5)

2010-06-30

Stephen Lang answers:

A handy plugin for manual redirects called 'Redirection' can do this and it comes with an easy to use interface (under Tools menu after install):
[[LINK href="http://wordpress.org/extend/plugins/redirection/"]]http://wordpress.org/extend/plugins/redirection/[[/LINK]]

If you want something automated, you'd need to run a query to check for child pages. I'd maybe go along the route of using get_posts() in some way. This example would print a list of child pages (max 5, ordered by date).


<ul>
<?php
global $post; // use if outside of the loop
$children = get_posts( 'post_parent=' . $post->ID . '&post_type=page&orderby=date&numberposts=5' ); // returns array of post objects

foreach($myposts as $post) :
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>



That should help you on your way, code will need to be tweaked depending on your theme of course. Documentation can be found here:
[[LINK href="http://codex.wordpress.org/Function_Reference/get_posts"]]http://codex.wordpress.org/Function_Reference/get_posts[[/LINK]]

2010-06-29

Buzu B answers:

I can help you with that. Send me a private message if you want me to solve it for you.

2010-06-30

Michael Fields answers:

Something like the following at the very top of your theme's page.php file should do the trick. I can help you with thematic specifics if need be. Please let me know how this works for you.
Best wishes,
-Mike

<?php
$child = get_children( "numberposts=1&post_type=page&post_status=publish&post_parent={$post->ID}&orderby=menu_order&order=ASC" );
if( !empty( $child ) ) {
$posts_backup = $posts[0];
foreach( $child as $id => $data )
$posts[0] = $data;
}
?>

2010-06-30

Oleg Butuzov answers:

i think will be better to use page redirects template. sample provided in attachment.

2010-06-30

Chris Lee answers:

This snippet redirects you to the first child of the template:

Make sure you switch templates for the particular page.


<?php
/*
Template Name: Redirect
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
}
}
?>