Function Reference/the widget

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

wordpress.org.cn

includeonlydiv style=clear:both; background-color:#FAEBD7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This page is marked as incomplete. You can help Codex by expanding it./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

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

Result

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

/noinclude

Description

This template tag displays an arbitrary widget outside of a sidebar. It can be used anywhere in templates.

Usage

%%% <?php the_widget( $widget, $instance, $args ); ?> %%%

Parameters

tt$widget/tt
(string) (required) The widget's PHP class name. The classes for the widgets included with WordPress are:
Default: Nonenoinclude

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

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$instance/tt
(array|string) (optional) The widget's instance settings. Either an array or query-style string. See each widget below for examples.
Default: array()noinclude

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

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$args/tt
(array|string) (optional) The widget's sidebar args. Either an array or query-style string. If empty, it defaults to:
before_widget
(string) the text or HTML befor the widget.
Default: <div class="widget {widget's classname}">
after_widget
(string) the text or HTML after the widget.
Default: </div>
before_title
(string) the text or HTML before the widget's title.
Default: <h2 class="widgettitle">
after_title
(string) the text or HTML after the widget's title.
Default: </h2>
Default: array()noinclude

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

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

Archives widget

Display a monthly archive list.

%%% <?php the_widget( 'WP_Widget_Archives', $instance, $args ); ?> %%%

  • widget's classname: widget_archive
  • instance:
    title
    The title of archive list. Default: __('Archives')
    count
    Display number of posts in each archive (1). The show_post_count parameter of wp_get_archives. Default: 0 (hide)
    dropdown
    Display as drop-down list (1). Dafault: 0 (an unordered list)

Examples

Default usage: %%% <?php the_widget( 'WP_Widget_Archives' ); ?> %%%

Display drop-down list: %%% <?php the_widget( 'WP_Widget_Archives', 'dropdown=1' ); ?> %%%

Calendar widget

Displays a Calendar.

%%% <?php the_widget( 'WP_Widget_Calendar', $instance, $args ); ?> %%%

  • widget's classname: widget_calendar
  • instance:
    title
    The title of calendar. Default:  

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Calendar' ); ?> %%%

Categories widget

Displays a list of categories.

%%% <?php the_widget( 'WP_Widget_Categories', $instance, $args ); ?> %%%

  • widget's classname: widget_categories
  • instance:
    title
    The title of categories list. Default: __( 'Categories' )
    count
    Display number of posts in each category. The show_count parameter of wp_dropdown_categories or wp_list_categories. Default: 0 (hide)
    hierarchical
    Display sub-categories as nested items inside the parent category (1). Default: 0 (in-line)
    dropdown
    Display as dropdown list (1). Default: 0 (an unordered list)

Examples

Default usage: %%% <?php the_widget('WP_Widget_Categories'); ?> %%%

Display a dropdown list with number of posts. %%% <?php the_widget( 'WP_Widget_Categories', 'dropdown=1&count=1' ); ?> %%%

Links widget

Displays an list of links (blogroll) in categories.

%%% <?php the_widget( 'WP_Widget_Links', $instance, $args ); ?> %%%

  • widget's classname:
  • instance:
    title
    The title of the Links section.
    category
    Link category IDs , separated by commas, to display. The category parameter of wp_list_bookmarks. Default: false (display all of link categories)
    description
    Display description of link (1 - true). The show_description parameter. Default: false (hide)
    rating
    Display rating of link (1- true). The show_rating parameter. Default: false (hide)
    images
    Display image of link (1 - true). The show_images parameter. Default: true (show)
    name
    If display link image, output link name to the alt attribute. The show_name parameter. Default: false

Examples

Default usage: %%% <?php the_widget( 'WP_Widget_Links' ); ?> %%%

Display lists in category IDs 2 or 3: %%% <?php the_widget( 'WP_Widget_Links', 'category=2,3' ); ?> %%%

Meta widget

Display site meta. (Log in/out, admin, feed and WordPress links )

%%% <?php the_widget( 'WP_Widget_Meta', $instance, $args ); ?> %%%

  • widget's classname: widget_meta
  • instance:
    title
    The title of meta section. Default: __( 'Meta' )

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Meta' ); ?> %%%

Pages widget

Display a list of Pages.

%%% <?php the_widget( 'WP_Widget_Pages', $instance, $args ); ?> %%%

  • widget's classname: widget_pages
  • instance:
    title
    The title of Pages list. Default: __( 'Pages' )
    sortby
    The sort_column parameter of wp_list_pages. Default: menu_order
    exclude
    Page IDs, separated by commas, to be excluded from the list. Default: null (show all of Pages)

Examples

Defaut udsage: %%% <?php the_widget( 'WP_Widget_Pages' ); ?> %%%

"<h3>Contents</h3> as the heading, sort by last modified date:

%%% <?php the_widget('WP_Widget_Pages', 'title=Contents&sortby=post_modified', 'before_title=

&after_title=

'); ?> %%%

Recent Comments widget

Display to a list of recent comments.

%%% <?php the_widget( 'WP_Widget_Recent_Comments', $instance, $args ); ?> %%%

  • widget's classname: widget_recent_comments
  • instance:
    title
    The title of comment list. Default: __( 'Recent Comments' )
    number
    Number of comments to show (at most 15). Default: 5

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Recent_Comments' ); ?> %%%

Recent Posts widget

Display to a list of recent posts.

%%% <?php the_widget( 'WP_Widget_Recent_Posts', $instance, $args ); ?> %%%

  • widget's classname: widget_recent_entries
  • instance:
    title
    The title of post list. Default: __('Recent Posts')
    number
    Number of posts to show (at most 15). Default: 10

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Recent_Posts' ); ?> %%%

RSS widget

Display a list of entries from any RSS or Atom feed.

%%% <?php the_widget( 'WP_Widget_RSS', $instance, $args ); ?> %%%

  • widget's classname:
  • instance :
    title
    The title of list
    Default: the title inherited from the RSS or Atom feed
    url
    RSS or Atom feed URL to include.
    items
    the number of RSS or Atom items to display
    show_summary
    show_author
    show_date

Example

Default usage: %%% <?php the_widget( 'WP_Widget_RSS' ); ?> %%%

Search widget

%%% <?php the_widget( 'WP_Widget_Search', $instance, $args ); ?> %%%

  • widget's classname: widget_search
  • instance:
    title
    The title of search form. Default: null

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Search' ); ?> %%%

Tag Cloud widget

%%% <?php the_widget( 'WP_Widget_Tag_Cloud', $instance, $args ); ?> %%%

  • widget's classname:
  • instance:
    title
    The title of tag cloud. default: __( 'Tags' )
    taxonomy
    The taxonomy the cloud will draw tags from. default: post_tag

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Tag_Cloud' ); ?> %%%

Text widget

%%% <?php the_widget( 'WP_Widget_Text', $instance, $args ); ?> %%%

  • widget's classname: widget_text
  • instance:
    • title
    • text
    • filter

Example

Default usage: %%% <?php the_widget( 'WP_Widget_Text' ); ?> %%%

Notes

  • Uses: global $wp_widget_factory - To retrieve the widget object.
  • Uses: do_action() - Calls 'the_widget' with $widget, $instance and $args.

Change Log

Source File

the_widget() is located in onlyincludecodewp-includes/widgets.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

Resources

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 - Source code for the widgets included in WordPress Core.

  • Ticket #9701 - Add a the_widget() function to output a generic widget anywhere in a template.

Related

Widgets API: is_active_sidebar, register_sidebars, register_sidebar, unregister_sidebar, is_dynamic_sidebar, dynamic_sidebar, register_sidebar_widget, unregister_sidebar_widget, wp_register_sidebar_widget, wp_unregister_sidebar_widget, wp_get_sidebars_widgets, wp_set_sidebars_widgets, is_active_widget, the_widget, register_widget, unregister_widget, register_widget_control, unregister_widget_control, wp_register_widget_control, wp_unregister_widget_control, wp_convert_widget_settings, wp_get_widget_defaults, wp_widget_description

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