WordPress:Good Navigation Links

来自站长百科
Xxf3325讨论 | 贡献2008年4月10日 (四) 09:24的版本 (新页面: __TOC__ It helps people move around your site when you have a clean navigation menu in the sidebar and/or the footer. It helps people find the posts and articles you want them to find. ...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

It helps people move around your site when you have a clean navigation menu in the sidebar and/or the footer. It helps people find the posts and articles you want them to find. There are a variety of methods for user friendly site navigation on your WordPress site.

Helping the user use your site means putting things where they can find them. Following the newsletter formats from the days of print, most website users are used to looking for intra-site links on the sides and bottom of a web page. As a designer, you can put them anywhere you want, but let's stick with the conventional placement for now. After all, we want our WordPress sites to be user-friendly, right?

In the two WordPress Themes that come with your WordPress installation, both use a sidebar to hold most of the site's navigation links. Other Themes may use navigational aids in the header and footer. While these navigation links can be displayed in any template file, typically, the navigation links include:

  • WordPress:Pages
  • [[WordPress:#Categories|Categories]]
  • [[WordPress:#Archives|Archives]] (by month)
  • Links
  • [[WordPress:#Admin_or_Meta|Admin or Meta]]

The template tags associated with generating this list of navigation links are found in the default WordPress Themes's sidebar inside of a nested list. Let's look at each of these tags individually and then look how to expand the use of navigational aids on your WordPress site.

Pages

With the introduction of WordPress v1.5, WordPress:Pages were available to help the administrator create individual Pages outside of the WordPress Loop such as Contact Us, About Us, and What's New. The template tags used to display the list of individual Pages is wp_list_pages().

<?php wp_list_pages(); ?>

There are many ways of customizing the wp_list_pages() tag to be more useful to your users. A long list of Pages and sub-Pages can go on for quite a while, so you might want to only feature the most important Pages in your sidebar.

To exclude some Pages from your list, you can set the parameters for exclude. The following example excludes Pages with the Page-ID numbers of 17 and 38.

<ul>
<?php wp_list_pages('exclude=17,38' ); ?>
</ul>

To learn more about customizing the wp_list_pages() template tag, visit the Template Tag page for wp_list_pages().

Categories

There are two template tags which create the category list in your navigation menu: wp_list_cats() and list_cats(). Both work basically the same but the first one uses boolean parameters and the second one uses strings. Which you use is up to you.

The default usage of the category list tags are:

<?php wp_list_cats(); ?>

<?php list_cats(); ?>

Again, like the [[WordPress:#Pages|Pages template tag]], you can use exclude to limit the categories you want listed, making it easier for the user to pick from only a few instead of twenty or thirty categories. The following example excludes category-IDs 10 and 15.

<ul>
<?php wp_list_cats('exclude=10, 15'); ?>
</ul>

If you would like only to feature the children or sub-categories of one or more categories in your category list, you can use the child_of parameter.

<ul>
<?php wp_list_cats('child_of=8, 14'); ?>
</ul>

To learn more about customizing the these template tags, visit the Template Tag page for wp_list_cats() and list_cats().

Archives

Like the [[WordPress:#Categories|categories]] template tags, there are two tags which produce the Archives date-based list of links: wp_get_archives() and get_archives(). Both work basically the same but the first one uses boolean parameters and the second one uses strings.

The Archive template tags are the only way to list posts in WordPress without a plugin. You can limit the number of posts to show in your Archives template tags, but you can't show all of them, only a limited number. The tag, however, will allow you to show the most recent by month, week, day, or the most recent posts.

The default usage of the archives list tags are:

<?php wp_get_archives(); ?>

<?php get_archives(); ?>

To show the most recent three months of posts by month, you would use the following:

<ul>
<?php get_archives('monthly','3'); ?>
</ul>

Displaying the archives by date, you can show the most recent 15 days worth of posts:

<ul>
<?php wp_get_archives('type=daily&limit=15'); ?>
</ul>

If you would like to show the actual posts, you can use the parameter postbypost which displays the most recent posts, with the number set by the limit parameter. To show the last 25 posts by post title:

<ul>
<?php wp_get_archives('type=postbypost&limit=25'); ?>
</ul>

To learn more about customizing the these template tags, visit the Template Tag page for get_archives() and wp_get_archives().


Links

The Links list of links come from WordPress' WordPress:Links Manager feature which allows displaying of external links, such as a blogroll, the user would like to feature on his or her site. These links are generated by several different template tags:

  • get_links_list: Displays a nested HTML unordered list of all links as defined in the Links Manager, sorted under link category headings.
  • wp_get_links: Displays links associated with a numeric link category ID.
  • get_links: Like wp_get_links(), this tag allows the user to control how the links are displayed by tag parameters, not through the Administration > Links Page (useful when displaying links on more than one template).
  • wp_get_linksbyname: Displays links associated with the named link category
  • get_linksbyname: Like wp_get_linksbyname(), this tag displays links by category, but allows the user to control how they are displayed by tag parameters.

For examples and more information on the specific use of each of these different template tags, click on the tag name above.

Admin or Meta

The Admin or Meta list of links in the WordPress sidebar are the links which are used by the Administrator, if logged in, to access the administration panels of the site. They may also feature RSS Feeds and other information related to the administration or use of the site. Check the following tags for more information on which ones you might want on your site to assist yourself and other registered users:

  • wp_register() - Registering on your site for comments and other administrative purposes
  • wp_loginout() - Logging in and out of your site's administration panel with a password
  • bloginfo() - Various parameters available for setting the RSS/Atomz/RDF feeds for the site and comments
  • WordPress:Template Tags - For more information on various template tags to use on your site

Other Navigation Locations

In addition to the sidebar, you can help your users navigate through your site with navigation tags used elsewhere, such as in the header and footer of your site. Using the above template tags for navigation links, you can style the link lists as horizontal menus instead of vertical lists.

Link to Posts and Pages

Often in these narrow areas, you may want to only highlight specific posts or WordPress:Pages to save space and direct the user to specific areas to continue their browsing. To include a specific link to a post or Page, you can use the get_permalink() template tag.

The following example presents links to post-ID numbers 1 and 10 and lists the categories on the site, excluding category-ID 2 and 4.

<li><a href="<?php echo get_permalink(1); ?>">About My Blog</a></li>
<li><a href="<?php echo get_permalink(10); ?>">About Me</a></li>
<?php wp_list_cats('exclude=2, 4'); ?>

The list might look like this:

  • [[WordPress:#Other Navigation Locations|About My Blog]]
  • [[WordPress:#Other Navigation Locations|About Me]]
  • [[WordPress:#Other Navigation Locations|My Stories]]
  • [[WordPress:#Other Navigation Locations|My Travels]]
  • [[WordPress:#Other Navigation Locations|My Friends]]


Next and Previous Posts

There are two other sets of navigational aids to consider as you design your site. Both of these sets involve moving a user through your site from one post to another.

The first set is featured only on the non-single/non-permalink web pages and is the template tag posts_nav_link(). This tag creates two links at the bottom of the page within the WordPress Loop to display the next and previous pages of the index, archives, searches, and categories.

By default, the posts_nav_link looks like this:

[[WordPress:#Other Navigation Locations|« Previous Page]] — [[WordPress:#Other Navigation Locations|Next Page »]]

To learn more about changing the look of this link, visit the Template Tag page for posts_nav_link().

The other set of navigational aids for moving through your site control the next post and previous post links typically found at the bottom of your single/permalink post. These direct the user to move to the next chronologically created post or the previous.

The template tags are previous_post() and next_post(). These can be styled in several different ways, using the next post and previous post titles or using the actual titles of the next and previous posts.

The following example displays the next and previous post titles with arrows to emphasis the direction the user may choose.

<?php previous_post('&laquo; &laquo; %', '', 'yes'); ?>
| <?php next_post('% &raquo; &raquo; ', '', 'yes'); ?>
[[WordPress:#Other Navigation Locations|« « Previous Post Title]]    |    [[WordPress:#Other Navigation Locations|Next Post Title » » ]]

To learn more about changing the look of these links, visit the Template Tag page for previous_post() and next_post().

Styling Your Navigation Links

As you have seen, there are a lot of ways WordPress uses to help the user move through a WordPress Site. We've shown you some of the WordPress template tags, but there are also many WordPress:Plugins available which also assist with site navigation such as providing related posts, customized post lists, and more to customize your site's navigation.

The following are some of the resources that may help you in stylizing and customizing your navigation lists.