文章      动态     相关文章     最新文章     手机版动态     相关动态     |   首页|会员中心|保存桌面|手机浏览

s14ol

http://sjzytwl.xhstdz.com/coms14ol/

相关列表
文章列表
  • 暂无文章
推荐文章
WordPress函数:the_widget(小工具)
发布时间:2025-01-03        浏览次数:11        返回列表

the_widget() 是一个模板标签,用来显示任何一个小工具。它可以在模板的任何地方使用。

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

widget

(字符串)小工具的 PHP 类名

  • WP_Widget_Archives —— Archives
  • WP_Widget_Calendar  —— Calendar
  • WP_Widget_Categories  —— Categories
  • WP_Widget_links  —— links
  • WP_Widget_meta  —— meta
  • WP_Widget_Pages  —— Pages
  • WP_Widget_Recent_Comments  —— Recent Comments
  • WP_Widget_Recent_Posts  —— Recent Posts
  • WP_Widget_RSS  ——  RSS
  • WP_Widget_Search  —— Search (a search from)
  • WP_Widget_Tag_Cloud  ——  Tag Cloud
  • WP_Widget_Text  —— Text
  • WP_Nav_Menu_Widget

instance

(数组或query-string-style)小工具的实例设置。具体请看下面的小工具示例。

args

(数组或query-string-style)小工具的侧边栏参数

  • before_widget

    (字符串)小工具前的文本或HTML代码

    默认值:<div class="widget {小工具的类名}">

  • after_widget

    (字符串)小工具后的文本或HTML代码

    默认值:</div>

  • before_title

    (字符串)小工具标题前的文本或HTML代码

    默认值:<h2 class="小工具标题">

  • after_title

    (字符串)小工具标题后的文本或HTML代码

    默认值:</h2>

显示每月存档列表

 <?php the_widget('WP_Widget_Archives', $instance, $args); ?> 
  • 小工具类名:widget_archive
  • instance:
    • titl

      存档列表的标题。默认值:__(‘Archives
    • coun

      显示每个存档的文章数(1)。wp_get_archives 的 show_post_count 参数。

      默认值:0 (隐藏

      可选:1 (显示)

    • dropdow

      以下拉菜单显示存档列

      默认值:0(无序列表)

      可选:1 (下拉列表)

示例

默认用法

<?php the_widget('WP_Widget_Archives'); ?> 

显示下拉列表

<?php the_widget('WP_Widget_Archives', 'dropdown=1'); ?> 

显示一个日历

<?php the_widget('WP_Widget_Calendar', $instance, $args); ?> 
  • 小工具类名:widget_calendar
  • instance:
    • title

      日历的标题,默认为空。

示例

默认用法

<?php the_widget('WP_Widget_Calendar'); ?> 

显示分类列表

<?php the_widget('WP_Widget_Categories', $instance, $args); ?> 
  • 小工具类名:widget_categories
  • instance:
    • title

      分类列表的标题。默认值:__( ‘Categories’ )
    • count

      显示每个分类的文章数。wp_dropdown_categories 或 wp_list_categories 的 show_count 参数。默认值:0(隐藏),可选:1(显示)
    • hierarchical

      以层级关系显示分类列表。默认值:0(不显示层级),可选:1(显示层级)
    • dropdown

      以下拉列表显示分类列表。默认值:0(无序列表),可选:1(下拉列表)

示例

默认用法

<?php the_widget('WP_Widget_Categories'); ?> 

下拉显示带文章篇数的分类列表

<?php the_widget('WP_Widget_Categories', 'dropdown=1&count=1'); ?> 

按分类显示链接

注:在 WordPress 3.5 以后默认去掉了链接管理功能,所以该小工具也默认不显示。如果要恢复,请看《恢复链接管理功能》

<?php the_widget('WP_Widget_links', $instance, $args); ?> 
  • 小工具类名:widget_links
  • instance:
    • title

      链接小工具的标题
    • category

      链接的分类ID,多个ID使用英文逗号隔开。wp_list_bookmarks 的 category 参数。默认值:false(显示所有链接分类)
    • description

      显示链接的描述。show_description 参数。 默认值:0 –false(隐藏),可选:1 – true(显示)
    • rating

      显示链接评级。show_rating 参数。默认值:0 –false(隐藏),可选:1 – true(显示)
    • images

      显示链接的图片。show_images 参数。默认值:1 – true (显示),可选:0 –false(隐藏)
    • name

      如果显示链接图片,输出图片的 alt 值。show_name 参数。默认:默认值:0 –false(隐藏),可选:1 – true(显示)

示例

默认用法

<?php the_widget('WP_Widget_links'); ?> 

显示分类ID为 2 或 3 的链接

<?php the_widget('WP_Widget_links', 'category=2,3'); ?> 

显示网站的meta信息(登录、登出,管理,Feed 和WordPress链接)

<?php the_widget('WP_Widget_meta', $instance, $args); ?> 
  • 小工具类名:widget_meta
  • instance:
    • title

      meta小工具的标题。默认值:__(‘meta’)

示例

默认用法

<?php the_widget(‘WP_Widget_meta’); ?>

显示页面列表

<?php the_widget('WP_Widget_Pages', $instance, $args); ?> 
  • 小工具类名:widget_pages
  • instance:
    • title

      页面列表的标题。默认值:__( ‘Pages’ )
    • sortby

      排列方式。wp_list_pages 的 sort_column 参数。默认值:menu_order
    • exclude

      页面ID,多个ID使用英文逗号隔开。从列表中排除某些ID的页面。默认值:null(显示所有页面)

示例

默认用法

<?php the_widget(‘WP_Widget_Pages’); ?>

使用<h3>Contents</h3>作为标题,根据最后修改日期排序

<?php the_widget('WP_Widget_Pages', 'title=Contents&sortby=post_modified', 'before_title=<h3>&after_title=</h3>'); ?> 

显示最近的评论

<?php the_widget('WP_Widget_Recent_Comments', $instance, $args); ?> 
  • 小工具类名:widget_recent_comments
  • instance:
    • title

      评论列表的标题。默认值:__(‘Recent Comments’)
    • number

      评论的显示数量(最多15条)。默认:5

示例

默认用法

<?php the_widget('WP_Widget_Recent_Comments'); ?> 

显示最近发布的文章

<?php the_widget('WP_Widget_Recent_Posts', $instance, $args); ?> 
  • 小工具类名:widget_recent_entries
  • instance:
    • title

      文章列表的标题。默认值:__(‘Recent Posts’)
    • number

      要显示的文章数量(最多15),默认:5

示例

默认用法

<?php the_widget('WP_Widget_Recent_Posts'); ?> 

显示来自任何RSS或Atom订阅的文章。

<?php the_widget('WP_Widget_RSS', $instance, $args); ?> 
  • 小工具类名:widget_rss
  • instance:
    • title

      文章列表的标题。默认值:订阅源的标题
    • url

      包含RSS或Atom订阅的URL
    • items

      要显示的RSS 或 Atom 项目的数量
    • show_summary

      显示文章摘要
    • show_author

      显示作者
    • show_date

      显示日期

示例

默认用法

<?php the_widget('WP_Widget_RSS'); ?> 

显示一个搜索表单

<?php the_widget('WP_Widget_Search', $instance, $args); ?> 
  • 小工具类名:widget_search
  • instance:
    • title

      搜索表单的标题。默认为空

示例

默认用法

<?php the_widget('WP_Widget_Search'); ?> 
<?php the_widget( 'WP_Widget_Tag_Cloud', $instance, $args); ?> 
  • 小工具类名:widget_tag_cloud
  • instance:
    • title

      标签云小工具的标题。默认值:__(‘Tags’)
    • taxonomy

      要显示的分类法。默认值:post_tag(文章标签)

示例

默认用法

<?php the_widget( 'WP_Widget_Tag_Cloud'); ?> 
<?php the_widget('WP_Widget_Text', $instance, $args); ?>
  • 小工具类名:widget_text
  • instance:
    • title

      文本小工具的标题。默认为空
    • text

      要显示的内容
    • filter

示例

默认用法

<?php the_widget('WP_Widget_Text'); ?> 

WordPress 3.0 添加的新的小工具。显示自定义菜单。

<?php the_widget('WP_Widget_Nav_Menu', $instance, $args); ?>
  • 小工具类名:widget_nav_menu

示例

默认用法

<?php the_widget('WP_Widget_Nav_Menu'); ?>

始用于 WordPress 2.8.0

WordPress 3.0 添加 WP_Nav_Menu_Widget