Function Reference/wp dropdown pages

来自WordPress中文文档
跳转至: 导航搜索

wordpress.org.cn

Description

Displays a list of pages in a select (i.e dropdown) box with no submit button.

Usage

%%% <?php wp_dropdown_pages( $args ); ?> %%%

Default Usage

%%% <?php $args = array( 'depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, 'name' => 'page_id'); ?>%%%

By default, the usage shows:

  • Pages and sub-pages displayed in hierarchical (indented) form
  • Displays all pages (not restricted to child pages)
  • No page is be 'selected' or presented in the display box
  • The name assigned to the dropdown form is 'page_id'
  • Allows you to select NONE of the pages (show_option_none=>'' not shown in above example)
  • Exclude no pages (exclude=>'' not shown in above example)
  • Exclude no 'tree' (exclude_tree=>'' not shown in above example)

Parameters

depth 
(integer)This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).
  • 0 - Pages and sub-pages displayed in hierarchical (indented) form (Default).
  • -1 - Pages in sub-pages displayed in flat (no indent) form.
  • 1 - Show only top level Pages
  • 2 - Value of 2 (or greater) specifies the depth (or level) to descend in displaying Pages.
child_of 
(integer) Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Defaults to 0 (displays all Pages).
selected 
(integer) Page ID of the page to be 'selected' or presented in the display box. Defaults to no page selected.
echo 
(boolean) Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 1 (display the generated list items). Valid values:
  • 1 (true) - default
  • 0 (false)
name 
(string) Name assigned to the dropdown form. Defaults to 'page_id'.
id 
(string) Id assigned to the dropdown form. Defaults to the name.
show_option_none 
(string) Causes the HTML for the dropdown to allow you to select NONE of the pages. If not empty, this string will be used as the option text.
option_none_value 
(string) The value attribute for the option that has show_option_none as its text.
show_option_no_change 
(string) Causes the HTML for the dropdown to allow you to select a NO CHANGE option with value -1.
exclude 
(string) Comma separated list of category IDs to exclude. For example, 'exclude=4,12' means category IDs 4 and 12 will NOT be displayed/echoed or returned. Defaults to exclude nothing.
exclude_tree 
(string) Define a parent Page ID to be excluded. Use this parameter to exclude a parent and all of that parent's child Pages. So 'exclude_tree=5' would exclude the parent Page 5, and its child Pages. This parameter was available at Version 2.7.

Other Parameters

It is possible, but not confirmed, some of the paramters for the function get_pages could be used for wp_dropdown_pages. Here's the default settings for the get_pages parameters

%%% <?php $args = array( 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => , 'include' => , 'meta_key' => , 'meta_value' => , 'authors' => , 'exclude_tree' => , 'post_type' => 'page' ); ?> %%%

With the 'post_type' parameter you can get a drop down of any post type, including custom post types, as long as the post type in question is hierarchical.

Examples

Dropdown with Submit Button

Displays a hierarchical page dropdown list in HTML form with a submit button.

<li id="pages">
 <h2><?php _e('pages:'); ?></h2>
   <form action="<?php bloginfo('url'); ?>" method="get">
   <?php wp_dropdown_pages(); ?>
   <input type="submit" name="submit" value="view" />
   </form>
</li>

Change Log

Since 2.1.0

Source File

wp_dropdown_pages() is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.

Parameters

  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.

Usage

Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre

/div

wordpress.org.cn.

Related

wp_list_authors, wp_list_categories, wp_list_pages, wp_list_bookmarks, wp_list_comments, wp_get_archives, wp_page_menu, wp_dropdown_pages, wp_dropdown_categories, wp_dropdown_users

includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude