Support » Fixing WordPress » How to: Parent page default to a child page?

  • Hello fellow WP’ers … I have a CMS section of a site working well by outputting the top-level pages for the “tabs” and the child pages for the “subnav.” The obvious benefit here is that no special coding is required and both menus highlight properly.

    My ideal scenario, when clicking on the Home tab:

    Home (tab)
    Welcome | Contact Us | Email Us (links)

    How do I get the Home tab to default to the first link in the subnav? As it sits, home is a link just like the “sublinks,” which isn’t 100% user-friendly to me. (It doesn’t appear to take the user anywhere in the nav, I’m expecting to see something get bold in the subnav.)

    How it looks now, when clicking on the Home tab:

    Home (tab)
    Welcome | Contact Us | Email Us (links)

    I’ve looked at the redirection plugins but am not convinced that’s the way to go. Am I missing something obvious?

    It seems like this would be a common question, but I can’t seem to find an answer. If anyone can keep me from hard-coding this, I’d greatly appreciate it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Since the Home is a Page in itself, the redirection method you’re describing would be the most obvious (and simplest) way to go.

    Another possibility would be some very custom code to have the main tab list output the names of the top level Pages, but output the links to the first child of those Pages.

    Hi Otto, that’s what I figured, but was not wishing for 🙂

    Maybe this can be a feature in the future?

    Thanks for a great product. You guys rock!

    I would also be VERY interested in functionality like this.

    As a temporary workaround: is there a way to have a dynamic link to the first child page?

    I found this: but I don’t know how to get it to work. From the description it looks like it should do what I want.

    Oh, and this also could be hacked, but alas, I’m a n00b…

    Sorry for the multiple posts… I contacted the author of above mentioned blog-post. He sent me the following code to put in my functions.php:

    function latest_page($id) {
     global $wpdb;
    $page_id = (int) $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' AND post_parent = '$id' ORDER BY post_date DESC LIMIT 1");
    	$page = get_page($page_id);
    	$uri = urldecode($page->post_name);
    	if ( $page->post_parent == $page->ID )
    		echo get_settings('home').'/'.$uri.'/';
    	while ($page->post_parent != 0) {
    		$page = get_page($page->post_parent);
    		$uri = urldecode($page->post_name) . "/" . $uri;
    echo get_settings('home').'/'.$uri.'/';

    Alas, it doesn’t work. I call the latest_page function and get no data at all. I’m not testing on a live page, so I don’t have a link for you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to: Parent page default to a child page?’ is closed to new replies.