WordPress.org

Ready to get started?Download WordPress

Forums

How to: Parent page default to a child page? (6 posts)

  1. sw33t
    Member
    Posted 6 years ago #

    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.
    :)

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. sw33t
    Member
    Posted 6 years ago #

    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!

  4. docflo
    Member
    Posted 6 years ago #

    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?

  5. docflo
    Member
    Posted 6 years ago #

    I found this: http://www.balauue.org/blog/2007/07/26/mysql-foerdert-den-wahnsinn/ 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...
    http://wordpress.org/support/topic/97628?replies=4

  6. docflo
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic