WordPress.org

Ready to get started?Download WordPress

Forums

Parent Page only in Sidebar (7 posts)

  1. Scribe
    Member
    Posted 8 years ago #

    I have searched the forum but most people are asking how to have the child pages only showing in the side bar, whereas I want the parent pages only to show.

    I did find a link that went to the codex but I didn't understand any of the content. Is there a simple coding which will let me have the parent pages showing, but not the child pages?

    This coding brings up all the pages:

    <?php wp_list_pages('title_li='); ?>

    What should I add to this so that only the parent pages show up?

    I'd be grateful for easy to understand instructions please.

  2. tomhanna
    Member
    Posted 8 years ago #

    From:

    http://codex.wordpress.org/Template_Tags/wp_list_pages

    depth
    (integer) Numeric value for how many levels of hierarchy (sub-pages) to display. Defaults to 0 (display all pages).

    So:

    <?php wp_list_pages('depth=1&title_li='); ?>

  3. Scribe
    Member
    Posted 8 years ago #

    It couldn't get any easier than that.

    Many thanks. :)

  4. HapaxLegomen
    Member
    Posted 8 years ago #

    More complicated : How to make appear the parent page title of the current page ???

    Whith wp_list_pages, I think it's impossible for the moment, isn't it ?

  5. Beel
    Member
    Posted 8 years ago #

  6. HapaxLegomen
    Member
    Posted 8 years ago #

    The idea is not to have a breadcrumb but a template tag, for the title of the page. Impossible with this plugin. I don't know how with WP.

  7. nearlythere
    Member
    Posted 8 years ago #

    you can get the name of the page parent and display it.

    you would need to use a custom page template. so i'm assuming you know how to make those.

    to make the parent name appear:
    first, you need to check if the page is a sub-page or not. if so, it should check for the parent name, and then display it.

    i use something like this: (i've simplified it here to do only what you asked)

    // check if this is a page
    if (is_page()) {
    $thispage = $wp_query->post;
    // check if this has a parent page
    if($thispage->post_parent!=0) {
    $parent_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = '$thispage->post_parent;'");
    // display parent name:
    echo ('<h2>' . $parent_title . '</h2>');
    }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags