WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專(zhuān)題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢(qián)
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專(zhuān)題
- 云計(jì)算
- 微博營(yíng)銷(xiāo)
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
WordPress:Plugins/WordPress Widgets Api
Widgets API
Widgets API
This page contains the technical documentation of the WordPress Widgets API (Application Programming Interface). The intended audience for this information includes WordPress theme authors, plug-in authors and anyone who would like to write a stand-alone widget. This document assumes a basic understanding of PHP scripting.
這個(gè)頁(yè)面包括了WordPress Widgets API(應(yīng)用程序接口)的技術(shù)文檔。WordPress主題作者,插件作者,以及任何想要編寫(xiě)卓越的widget的人,都想要查看這個(gè)信息。閱讀這個(gè)文檔的前提是基本了解PHP腳本。
A widget is a PHP function that echoes string data to STDOUT when called. To turn such a PHP function into a Wordpress Widget it must be registered as such. This is done using a PHP callback (a Pseudo-Type in PHP documentation) that is registered by a wordpress widget API function.
Widget是個(gè)PHP 函數(shù)調(diào)用時(shí),向STDOUT反映字符串?dāng)?shù)據(jù)。要將這樣的PHP函數(shù)轉(zhuǎn)變?yōu)閃ordpress Widget,必須像這樣注冊(cè)。使用 PHP callback (PHP文檔中的 準(zhǔn)型),由wordpress widget API函數(shù)注冊(cè),可以操作。
register_sidebar_widget($callback);
register_sidebar_widget($callback);
The Wordpress widget API is located in wp-includes/widgets.php. It is advised to not use the functions starting with wp_ as these could change in subsequent releases. This is why we use register_sidebar_widget() instead of wp_register_sidebar_widget().
Wordpress widget API位于wp-includes/widgets.php。建議不要使用,以wp_開(kāi)頭的函數(shù),因?yàn)檫@些函數(shù)在隨后的版本中會(huì)變化。這就是我們使用register_sidebar_widget()而不是使用wp_register_sidebar_widget()函數(shù)的原因。
Function Reference
函數(shù)參考
|
Developing New Widgets
開(kāi)發(fā)新的Widgets
The Google Search widget is commented within inches of its life, so consider that your tutorial. Additionally, there are a few guidelines to follow:
Google 搜索widget注釋盡在咫尺,因此考慮將這個(gè)作為你的指南。此外,需要遵循一些指導(dǎo)方針:
- Don’t execute any code while the plugin is loaded. Use the plugins_loaded hook or you risk fatal errors due to undefined functions, or missing the boat completely because your plugin loaded before the one it depends on.
- 載入插件的時(shí)候,不要運(yùn)行任何代碼。使用plugins_loaded hook或者因?yàn)槲炊x的函數(shù),或者因?yàn)槟愕牟寮贈(zèng)]有依賴(lài)函數(shù)的情況下,載入,你坐失良機(jī),冒著致命錯(cuò)誤的危險(xiǎn)。
- Use register_sidebar_widget($name, $callback) to add your widget to the admin interface.
- 使用register_sidebar_widget($name, $callback)將你的widget添加到管理界面。
- Follow this template:
- 遵循下面的模板:
function widget_myuniquewidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . 'My Unique Widget' . $after_title; ?> Hello, World! <?php echo $after_widget; ?> <?php } register_sidebar_widget('My Unique Widget', 'widget_myuniquewidget');
function widget_myuniquewidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . 'My Unique Widget' . $after_title; ?> Hello, World! <?php echo $after_widget; ?> <?php } register_sidebar_widget('My Unique Widget', 'widget_myuniquewidget');
- Don’t leave out $before_widget, $after_widget, $before_title, or $after_title by accident. They are required for compatibility with various themes.
- 不要碰巧遺漏了$before_widget, $after_widget, $before_title, 或者$after_title。需要這些函數(shù)與不同的主題兼容。
- Name your widget and its functions carefully. Those strings will be used as HTML attributes and you don’t want to cause identical id’s in a single HTML document.
- 仔細(xì)地命名你的widget和函數(shù)。這些字符串將會(huì)用作HTML屬性而且你不希望在單一的HTML文檔中產(chǎn)生同樣的id’s。
- Localization is done internally to preserve the HTML id attribute. If you want your widget name localized with a textdomain, pass array($name, $textdomain) instead of $name.
- 本地化是在內(nèi)部完成的,保留HTML id 屬性。如果你希望能使用文本域名本地化你的widget名稱(chēng),請(qǐng)傳遞array($name, $textdomain)而不是$name。
- To accommodate multi-widgets (e.g. Text and RSS) you can also pass a replacement value with the name: array($name_as_sprintf_pattern, $textdomain, $replacement). See the source.
- 要容納多個(gè)widgets(例如文本和RSS),你可以使用下面的名稱(chēng)傳遞replacement參數(shù)值:array($name_as_sprintf_pattern, $textdomain, $replacement)。請(qǐng)看看原始資料。
- You may use the variables mentioned above in different ways, or neglect them in some circumstances. Some widgets may not need a title, for example. Some widgets will use the $before_widget and $after_widget several times, or as arguments to tell another template tag how to format its output.
- 你可能以不同的方式使用上述提到的變數(shù),或者在有些情況下,忽視這些變數(shù)。一些widgets可能不需要標(biāo)題。有的widgets幾次都用到$before_widget 和 $after_widget,或者作為參數(shù)通知其它模板標(biāo)簽怎樣為輸出內(nèi)容設(shè)計(jì)格式。
- Optionally, use the following syntax to add a configuration page to the admin. Your callback will be used within the main form, so you must not include any <form> tags or a form submit button.
- 使用下面的語(yǔ)法將配置頁(yè)面添加到管理。在主要的表格中會(huì)用到你的callback,因此你不應(yīng)該包含任何<form>標(biāo)簽或者表格遞交按鈕。
register_widget_control($name, $callback [, $width [, $height ]] );
register_widget_control($name, $callback [, $width [, $height ]] );
- Namespace your form elements so they don’t conflict with other widgets.
- 給你的表格內(nèi)容定義名字空間,這樣與其它的widgets不會(huì)發(fā)送沖突。
- Each widget must have a unique name. You can replace an already-registered widget by registering another one with the same name, supplying your own callback.
- 每個(gè)widget必須有個(gè)單獨(dú)的名稱(chēng),你可以通常同樣名稱(chēng)的widget,替換已注冊(cè)的widget,支持你自己的callback。
- Any extra arguments to register_sidebar_widget() or register_widget_control() will be passed to your callback. See the Text and RSS widgets for examples.
- register_sidebar_widget()或者register_widget_control()的任何額外參數(shù)會(huì)傳遞到你的callback。請(qǐng)看看文本和RSS widget,作為例子參考。
- Any widget or control can be “unregistered” by passing an empty string to the registration function.
- 向注冊(cè)函數(shù)傳遞空字符串,可以“取消注冊(cè)”任何widget或者control。
- There are probably some undocumented functions. You are encouraged to read the source code and see how we’ve created the standard widgets using these functions.
- 可能有一些違歸檔的函數(shù)。鼓勵(lì)你閱讀源代碼,了解我們?cè)鯓邮褂眠@些函數(shù),創(chuàng)建了標(biāo)準(zhǔn)的widgets。
- Please test your widgets with several themes other than Classic and Default (they both use the ul/li/h2 markup).
- 除了經(jīng)典和默認(rèn)主題(都使用ul/li/h2標(biāo)記),請(qǐng)使用多個(gè)主題測(cè)試你的widgets。
- Please audit the security of your widgets before distributing them.
- 發(fā)行widgets之前,請(qǐng)審核widgets的安全性。
- If you would like your widget to be considered for use on WordPress.com, send a link (no attachments please) to widgets@wordpress.com and we’ll have a look.
- 如果你希望你的widget在WordPress.com上使用,請(qǐng)發(fā)送鏈接(不要加附件)到widgets@wordpress.com,我們會(huì)查看你的widget。
What else can I do with Widgets?
我還可以怎樣處理Widgets?
You have no idea how glad we are that you asked that. Here are a few ideas:
你不知道,你提出了這個(gè)問(wèn)題,我們有多高興。下面是一些建議:
- Write a theme that includes a special widget to set it apart from the others.
- 編寫(xiě)主題包含某個(gè)widget,將這個(gè)widget與其它的分開(kāi)。
- How about this for a special widget: a WordPress loop to show asides.
- 為某個(gè)widget使用這個(gè)怎樣:WordPress loop顯示asides。
- Register a replacement widget that buffers the original widget and transforms it somehow.
- 注冊(cè)replacement widget,buffer最初的widget并且將其轉(zhuǎn)變。
- Remember that a “sidebar” is really just a name for a list. It can be displayed vertically or horizontally.
- 記住“邊欄”真的只是列表的名稱(chēng)??梢运交蛘哓Q直顯示。
- Remember that a “widget” is really just a name for a configurable code snippet. It can be invisible or it can be absolutely positioned.
- 記住“widget”真的只是可配置的代碼snippet的名稱(chēng)??梢允菬o(wú)形的,或者可以完全地放置。
- Use the id and class attributes of any or all widgets in scripts to animate your sidebar.
- 使用腳本中的任何或者所有widgets的id和class屬性,裝飾你的邊欄。
- Heck, use script.aculo.us or dbx (included with WordPress) to make your widgets draggable or even collapsible. Ain’t scripting sweet?
- Heck,使用script.aculo.us 或者 dbx(包含在WordPress中),使得你的widgets可以拖拉或者collapsible。Ain’t scripting sweet?
- Remember that the widget control API is just for convenience. You can always set up your own admin page instead.
- 記住widget control API只是為了方便使用。你也可以經(jīng)常設(shè)置你自己的管理頁(yè)面。
- Support your users and get feedback so you can improve your widget. Put a link to your email or your site at the bottom of your widget control.
- 支持你的用戶(hù)并且經(jīng)常得到反饋,這樣你能夠改善你的widget。向你的電子郵件或者你的widget控制底部的你的站點(diǎn)添加鏈接。
- Send a link to your widgets to widgets@wordpress.com for review. We might put them up for everyone to use on WordPress.com. You could be internet famous!
- 發(fā)送鏈接到你的widgets到widgets@wordpress.com以便查看。我們可以建議任何人都在WordPress.com 上使用這個(gè)widget。你就在網(wǎng)絡(luò)上出名了!
Widgets - One or many
Widgets –一個(gè)或者許多
Widgets can be coded so that they can exist one time or they can exist multiple times. Wordpress is doing the work for you to instantiate your Widget multiple times if you follow some rules.
Widgets可以再次編碼,這樣可以只存在一次或者多次。如果你遵循一些規(guī)則,WordPress會(huì)為你多次例示W(wǎng)idget。