WordPress

wordpress

#1

Hello. Does anyone know how to get wp_list_pages() to include the homepage (index) in the list it generates? Thanks.

Correctness Commentary


#2

Did you see the WordPress Codex Article on wp-list (linked to including pages section) ?

I think what you need is there! :wink:

–rlparker


#3

Yes, that’s what I thought was needed, but when I specify a page index of 1, nothing changes. Is the default WordPress home page have a different index?

Correctness Commentary


#4

Ah! I understand better now what you are trying to do, but I think you are going about it the wrong way. :wink:

First of all, it is important to understand fully what WordPress considers a “Page” for the purposes of the wp_list_pages() function.

The WordPress Codex has a very good discussion of what constitutes a “Page”, and upon reviewing that resource, you will find that the “index.php” default “home” page of WordPress is not a “Page” that can be used with the wp_list_pages() function; it does not have an id as do the other “Pages” that are created by WordPress (as opposed to posts, etc.).

Don’t be discouraged, though, as there are a couple of ways to “workaround” this situation:

  1. Use WordPress’s ability to create and use a WordPress “Page” for a site “homepage” to load upon visiting the site instead of the “default” blog-style dynamically created “index” homepage. This page would have an ID associated with it, and could then be included in the output of the wp_list_pages() function. (unlike the default “index” which, while it is displayed as a “homepage”, cannot be “automagically” included in a wp_list_pages generated link list because is is not a “Page” with an ID in the WordPress structure).

  2. If you want to continue to use the default “index” as your homepage, but have a Menu link to it “with” the link list generated by wp_list_pages() function (which is what I think you want to do) you can simply include/embed the appropriate link code for the index file into the appropriate place on your page template(s). For instance, if you want the output of wp_list_pages to be displayed in a sidebar, with the “Home” link pointing to the default index page, you can do it using a code snippet similar to this (from WP wizard Lorelle in this WordPress support forum thread - my emphasis in red):

[quote]
In your WordPress Theme files, find sidebar.php. This is your sidebar template file.

Every WordPress Theme has similar but different structure for the sidebar links. You will want to look for something labeled “Pages”, though it might be different for your Theme.

The “correct” structure, replacing the information with your URL and desired effect, would be:

The above example includes:

  • A link to your home page (index.php)
  • A link to a specific category of posts you might want to feature
  • A link to an external blog, such as another blog of yours or a favorite blog you recommend
  • A link to a specific post (or Page) you may want to feature
  • A list of links to your blog Pages (like About, Contact, etc.) which does not include category IDs for 2, 6 and 4, nor subPages. The list of Pages is in menu order and includes other formating instructions.

You can mix and match and order this anyway you like in the sidebar.php template file.

This same structure can work for featuring “static” links in the footer and header if desired. [/quote]
Of course, this concept works in other places besides the sidebar; you can do something similar in another template section if you so desire. :wink:

In summary, “index.php” is not a “Page” than can be displayed by the wp_list_pages() function (it has no Page_ID), but you can workaround the issue to include a “Home” link as described in either method above. Does that help at all?

–rlparker


#5

This issue is now resolved. Thanks for the help! :smiley:

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

Correctness Commentary


#6

Very good! I’m glad you got it sorted out! :slight_smile:

Personally, I agree that it is easier to do it that way than to create a “dummy” page just so it is included in the “list”. Your code:

  • Home
  • is, in the case of the WordPress structure, the functional equivalent of the example:

  • Home
  • from the previous example I provided, and works just fine! :wink:

    –rlparker