WordPress.org

Ready to get started?Download WordPress

Forums

Remove dupe listing of static page from wp_list_pages display (7 posts)

  1. drmike
    Member
    Posted 7 years ago #

    Greets:

    When one uses a static Page for a blog's home page, wordpress leaves in the Page link in output from the wp_list_pages template call. In that case you wind up with what amounts to two links to the same content, once to the front page via a hard coded home link and once to the specific page.

    I'd rather not just edit the theme file to exclude the specific page as the client in question probably shouldn't be editing files. And the theme has a hard coded home link and it's design limits removing it.

    Is there anyway to have wp_list_pages not display a link to a static front page?

    Thanks,
    -drmike

  2. BPartch
    Member
    Posted 7 years ago #

    Hello

    <?php wp_list_pages('exclude=1'); ?>

    The 1 after the exclude= is the ID number of the page you want excluded. I hope this is what you we're after. :)

  3. moshu
    Member
    Posted 7 years ago #

    You are right... except that drmike said:
    I'd rather not just edit the theme file to exclude the specific page as the client in question probably shouldn't be editing files.

  4. BPartch
    Member
    Posted 7 years ago #

    Oops, I guess you are right he did say that. :)

    Though if you remove it this way how will the client ever need to edit it again, unless the homepage changes at some point?

    Maybe I am just missing the point. :)

  5. drmike
    Member
    Posted 7 years ago #

    Yeah, I was looking at the exclude bit. I'd hate to do:

    `wp_list_pages('exclude=get_option('page_on_front')');

    as I would think that, since the exclude isn't cached, it would build that list each and every time but I guess that's the way it's going to be.

    Or would it be cached?

    We roll out a couple hundred installs across a number of servers. I would hate to have to do this manually with each and every client when they change their setup. And, as noted, some of these clients still have issues with uploading images so I'd rather not tell them to edit the files.

    I'd actually call this a bug as it is listing the same page twice if you have a hard coded home link within the theme but since the same function is used within the sidebar and the widgets, I'd rather just edit the header.php file for each theme and roll that out.
    It's a pain actually.

    edit: Ooh, someone actually answered one of my posts. :)

  6. drmike
    Member
    Posted 7 years ago #

    OK, I worked out a bit of code specific to the theme. Gotta admit that I would rather have it within the wordpress code though.

    <?php
    $tmpexclude =  get_option('page_on_front');
    $tmpline = 'sort_column=menu_order&depth=1&title_li=&exclude=' . $tmpexclude;
    wp_list_pages($tmpline);
    ?>

    So, would you call this a bug or what? Gotta admit that I don't feel comfortable with submitted a trac ticket on the subject.

  7. dolfelt
    Member
    Posted 6 years ago #

    You could always do something like this, which would allow anyone to use it without changing the template:

    $options_wp_list = 'title_li=&depth=1&sort_column=menu_order';
    if(get_option('show_on_front')=='page') {
        $options_wp_list .= '&exclude=' . get_option('page_on_front');
    }
    wp_list_pages($options_wp_list);

    That checks to see if a page is set as the static front page, and if it is, it excludes it from the list.

Topic Closed

This topic has been closed to new replies.

About this Topic