當前位置:首頁>WordPress建站>WordPress開發(fā)>WordPress函數(shù):the_widget(小工具)

WordPress函數(shù):the_widget(小工具)

說明

the_widget() 是一個模板標簽,用來顯示任何一個小工具。它可以在模板的任何地方使用。

用法

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

參數(shù)

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

(數(shù)組或query-string-style)小工具的實例設置。具體請看下面的小工具示例。

args

(數(shù)組或query-string-style)小工具的側邊欄參數(shù)

  • 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

      顯示每個存檔的文章數(shù)(1)。wp_get_archives 的 show_post_count 參數(shù)。

      默認值: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

      顯示每個分類的文章數(shù)。wp_dropdown_categories 或 wp_list_categories 的 show_count 參數(shù)。默認值:0(隱藏),可選:1(顯示)
    • hierarchical

      以層級關系顯示分類列表。默認值:0(不顯示層級),可選:1(顯示層級)
    • dropdown

      以下拉列表顯示分類列表。默認值:0(無序列表),可選:1(下拉列表)

示例

默認用法

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

下拉顯示帶文章篇數(shù)的分類列表

<?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 參數(shù)。默認值:false(顯示所有鏈接分類)
    • description

      顯示鏈接的描述。show_description 參數(shù)。 默認值:0 –false(隱藏),可選:1 – true(顯示)
    • rating

      顯示鏈接評級。show_rating 參數(shù)。默認值:0 –false(隱藏),可選:1 – true(顯示)
    • images

      顯示鏈接的圖片。show_images 參數(shù)。默認值:1 – true (顯示),可選:0 –false(隱藏)
    • name

      如果顯示鏈接圖片,輸出圖片的 alt 值。show_name 參數(shù)。默認:默認值:0 –false(隱藏),可選:1 – true(顯示)

示例

默認用法

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

顯示分類ID為 2 或 3 的鏈接

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

Meta小工具

顯示網(wǎng)站的Meta信息(登錄、登出,管理,F(xiàn)eed 和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 參數(shù)。默認值:menu_order
    • exclude

      頁面ID,多個ID使用英文逗號隔開。從列表中排除某些ID的頁面。默認值:null(顯示所有頁面)

示例

默認用法

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

使用<h3>Contents</h3>作為標題,根據(jù)最后修改日期排序

<?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

      評論的顯示數(shù)量(最多15條)。默認:5

示例

默認用法

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

最新文章小工具

顯示最近發(fā)布的文章

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

      文章列表的標題。默認值:__(‘Recent Posts’)
    • number

      要顯示的文章數(shù)量(最多15),默認:5

示例

默認用法

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

RSS小工具

顯示來自任何RSS或Atom訂閱的文章。

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

      文章列表的標題。默認值:訂閱源的標題
    • url

      包含RSS或Atom訂閱的URL
    • items

      要顯示的RSS 或 Atom 項目的數(shù)量
    • 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'); ?>

函數(shù)歷史

始用于 WordPress 2.8.0

WordPress 3.0 添加 WP_Nav_Menu_Widget

注:本文的某些小工具的介紹和使用方法還沒有補充完整,如果你有興趣,歡迎進行補充完善,投稿給我們,謝謝。

  • 原文:http://codex.wordpress.org/Function_Reference/the_widget
  • 編譯:倡萌@WordPress大學
聲明:本站所有文章,如無特殊說明或標注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發(fā)布本站內容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯(lián)系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
歡迎關注WordPress大學公眾號 WPDAXUE
WordPress開發(fā)

WordPress函數(shù):is_active_widget(已使用小工具)

2013-5-5 9:14:47

WordPress開發(fā)

WordPress函數(shù):wp_page_menu(頁面菜單)

2013-5-11 8:28:24

0 條回復 A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索

嵊泗县| 榆树市| 铁岭县| 黑河市| 汝城县| 巍山| 桐城市| 名山县| 大城县| 太白县| 电白县| 蛟河市| 合山市| 丰台区| 大英县| 葫芦岛市| 中山市| 贵港市| 东山县| 克什克腾旗| 南江县| 巢湖市| 米泉市| 绥宁县| 衢州市| 南投县| 大庆市| 全椒县| 株洲县| 宁明县| 略阳县| 辽中县| 旺苍县| 西畴县| 哈巴河县| 济宁市| 奉化市| 伊金霍洛旗| 台前县| 麻城市| 长兴县|