logo

$15
display child page rather than parent page

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.

karenmessing | 06/29/10 at 7:44pm | Edit


(5) Possible Answers Submitted...

  • avatar
    Last edited:
    06/29/10
    7:49pm
    Buzu B says:

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

  • avatar
    Last edited:
    06/29/10
    8:06pm
    Michael Fields says:

    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;
    }
    ?>

    Previous versions of this answer: 06/29/10 at 8:06pm

  • avatar
    Last edited:
    06/29/10
    9:59pm
    Stephen Lang says:

    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):
    http://wordpress.org/extend/plugins/redirection/

    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:
    http://codex.wordpress.org/Function_Reference/get_posts

  • avatar
    Last edited:
    06/29/10
    9:02pm
    Oleg Butuzov says:

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

    attachment image View Attachment

  • avatar
    Last edited:
    06/29/10
    9:21pm
    Chris Lee says:

    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));
    }
    }
    ?>

This question has expired.





Current status of this question: Completed