WordPress:Template Tags/wp dropdown pages

来自站长百科
Xxf3325讨论 | 贡献2008年6月27日 (五) 09:54的版本 (新页面: {{Copyedit}} == Description == Displays a list of pages in a select (i.e dropdown) box with no submit button. == Usage == %%% <?php wp_dropdown_pages('arguments'); ?> %%% == Examples ==...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.

Description

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

Usage

%%% <?php wp_dropdown_pages('arguments'); ?> %%%

Examples

Default Usage

$defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 
'echo' => 1,'name' => 'page_id', 'show_option_none' => '');

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)
<?php wp_dropdown_pages(); ?>

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>

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'.
show_option_none
(string) Causes the HTML for the dropdown to allow you to select NONE of the pages.
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.

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

$defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '');

Related

模板:Tag General Tags

模板:Query String Tag Footer