The wp_list_pages() function supports several parameters that allow you to change the way pages are listed. By default, all pages will be listed in alphabetical order. Listing 6-27 shows several alternatives. See codex.wordpress.org/Template_Tags/wp_list_pages for the full list of available parameters and their default settings.
Listing 6-27. Using the wp_list_pages function
<!-- all pages in alphabetical order --> <ul> <?php wp_list_pages(); ?> </ul> <!-- all pages in menu order -->
<ul> <?php wp_list_pages('sort_column=menu_order'); ?> </ul>
<!-- to exclude a single page (in this case, the one with an ID of 12) -->
<ul> <?php wp_list_pages('sort_column=menu_order&exclude=12'); ?> </ul>
There's a second function that you can use for a few extra options in your page lists: wp_page_menu(). This is essentially a clone of wp_list_pages() that has just a few extra features. It includes the <ul> tags, so you don't have to specify those separately. It includes a menu_class parameter so you can still style the list using your own class names. This function also adds a "Home" link to the page list, as shown in Listing 6-28.
Listing6-28. Using the wp_page_menu function
<!-- all pages in menu order, then alphabetically by page title --> <?php wp_page_menu(); ?>
<!-- the above, plus a 'home' link, with a different class on the <ul> --> <?php wp_page_menu('show_home=true&menu_class=nav'); ?>
These parameters give you a great deal of flexibility in creating your navigation menus, but you will quickly discover that WordPress's page management features are a little lacking when it comes to creating the navigation for a complicated site. Changing the page order, choosing which pages are included or excluded, and linking to external sites are all much harder to accomplish with page lists than with the navigation menus.
To rearrange pages, simply change the number in the Order box, as shown in Figure 6-11. It's a little like writing a program in BASIC: if you need to insert a page between the existing ones, you'll have to redo the numbering on the entire sequence.
Main Page (no parent) i
You can arrange your pages in hierarchies. For example, you could have an "About" page that has ''Life Story" and "My Dog* pages under it. There are no limits to how deeply nested you can make pages.
Default Template i
Some themes have custom tempiates you can use for certain pages that might have additional features or custom layouts, if so, you'll see them above.
Pages are usuaHy ordered alphabetically, but you can put a number above to change the order pages appear in.
Figure 6-11. The menu order field in the page Attributes box
My Page Order
Choose a case from the drop down to order its subcases or ordet the pages on this level by dragging and dropping them into (he desired order.
Parent page ; Order Subpagea
Parent page ; Order Subpagea
Page with com men is
Page with comments disabled
Ciick to Order Pages
Figure 6-12. The My Page Order plugin
The Quick Edit feature makes it a little easier to order several pages at a time, but editing a field for each page is still more tedious than it ought to be. There are a few plugins that make the process much easier.
My Page Order is the simplest way to reorganize your pages in WordPress. It provides a drag-and-drop editing screen (Figure 6-12) for all your top-level pages and a dropdown list of all the pages that have subpages. Choose one of those, and you can rearrange all the pages on that level as well.
PageMash (Figure 6-13) offers a similar drag and drop interface. It expands the first level of subpages and gives you arrows to expand others as needed. You can change not only the order but the depth of each page by dragging it under another page in the list.
pageMash - pageManagement
Just drag the pages up or down Co change the page order and left or right to change the page s parent, then hit "update . The icon to the left of each page shows if it has child pages, double click on that Hem to toggle expand collapse of it's children.
Expand AH ] CoJ lapse AH Q About fjlj About
Parent page I Child page 1 Q Child page 2
Larem Ipsum Q Page with comments D Page with comments disabled Q Level 1 □ Level 2 Q Level 3
Figure 6-13. The PageMash plugin
Changing Which Pages are Listed
Rather than changing your theme files every time you need to exclude another page from the menu, consider installing a plugin that will allow you to exclude pages from all page list template tags.
Exclude Pages, shown in Figure 6-14, provides a checkbox on the page editing screen that will allow you to decide whether the page should be included in menus.
Pages are usually ordered alphabetically* but you can put a number above to change the order pages appear in.
Exclude Pages iV1 Include this page in user menus
Set featured image
Figure 6-14. The Exclude Pages plugin
Page Lists Plus offers a long list of useful global settings, such as Exclude children of excluded pages. It also allows administrators to specify which options will appear to content authors on individual pages. In addition to choosing whether the page will appear in menus, the author can change the link text, specify custom classes, and even redirect visitors to some other URL.
Including Links to Things Outside WordPress
Sometimes you need to link to something other than a WordPress page in your navigation menu. Perhaps you've built a photo gallery in ZenPhoto. How do you get it into your menu without hand-coding the link every time the menu appears in a theme file?
The Page Lists Plus plugin mentioned above includes just such a feature, but if you want something simpler, try Page Links To (Figure 6-15). Install the plugin, then create a blank post or page with the title of your desired menu item. Scroll down to the Page Links To section of the edit screen and enter the URL of your external page.
Page Links To
Fointto this URL: http:/y example.com Q Open this link in a new window
Use a temporary 30Z redirect (default ¡5 a permanent 361 redirect)
Figure 6-15. The Page Links To plugin
The disadvantage of this plugin is that it clutters up your Page ^ Edit screens with a bunch of placeholder pages.
Was this article helpful?