Support » Fixing WordPress » Parent Page only in Sidebar

  • 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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • From:

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


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

    It couldn’t get any easier than that.

    Many thanks. 🙂

    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 ?

    There are “Breadcrumb” plugins out there.

    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.

    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>');

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Parent Page only in Sidebar’ is closed to new replies.