[WordPress] 外掛分享: Duplicate Widget

首頁外掛目錄 › Duplicate Widget
1,000+
安裝啟用
★★★★
4.3/5 分(12 則評價)
3045 天前
最後更新
問題解決
WordPress 3.1+ v1.0.2 上架:2011-12-11

內容簡介

r />

一個小工具,可以作為另一個小工具的副本(用於在另一個側邊欄中同步使用)

只需定義一次小工具,即可在多個側邊欄中使用。這樣可以避免手動配置每個小工具的麻煩,並且在以後需要進行任何更改時,也可以省去保持它們同步的煩惱。特別適用於在其主題中定義邏輯以有條件地包含不同版本的側邊欄的人。根據使用情況,這是應用於決定何時顯示小工具的小工具邏輯的替代方案(Widget Logic、Section Widget、條件小工具等)。

此外,快速概述此插件的功能:

添加一個名為“Duplicate”的小工具。小工具的唯一設置是下拉菜單,其中列出所有活動小工具。所選小工具將是副本小工具要複製的小工具。
副本小工具顯示的標題和內容與其源小工具相同,即使這些值稍後在源小工具中更改。
可以將小工具複製任意次數,在同一頁面中可以出現多次(是的,即使在同一個側邊欄中,為什麼要這樣做呢?)
副本小工具將遵循其放置的側邊欄的配置,而不是源小工具的側邊欄的配置。因此,副本小工具使用自己側邊欄的“before_widget”、“after_widget”、“before_title”、和“ after_title”值。
複製的小工具在管理員小工具標題欄中的名稱中預置“[D]”,以表示它們有副本。此外,在展開小工具並向下滾動時,也會在小工具的配置表單底部顯示一個簡短的説明,該説明說明小工具有幾個副本。
如果某個小工具被停用或刪除,如果它有任何副本,這些副本也會被刪除。
在複製小工具的標記中包含源小工具的小工具ID和小工具類型。

鏈接:插件主頁面 | 插件目錄頁面 | 作者主頁面

篩選器

該插件公開了四個操作以進行鉤取。定制利用這些鉤子的通常放在您正在使用的主題的 functions.php 文件中,或被其他插件使用。

c2c_before_duplicate_widget(動作)

“c2c_before_duplicate_widget”鉤子允許你在副本小工具輸出之前輸出文本或執行某些操作。

參數:

$ instance(array):小工具實例的設置(即:標題和widget_to_duplicate)
$ args(array):小工具和側邊欄的配置

示例:

//在複製小工具內容前輸出開始的 <div>
add_action(‘c2c_before_duplicate_widget’,‘my_c2c_before_duplicate_widget’,10,2);
function my_c2c_before_duplicate_widget($ instance,$ args){
echo ‘<div class =“a_duplicate_widget”>;
}。
c2c_after_duplicate_widget(動作)

“c2c_after_duplicate_widget”鉤子允許你在副本小工具輸出之後輸出文本或執行某些操作。

參數:

$ instance(array):小工具實例的設置(即:標題和widget_to_duplicate)
$ args(array):小工具和側邊欄的配置

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Duplicate Widget」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

A widget that can act as a duplicate of another widget (for synchronized use in another sidebar)
Define a widget once, use it in multiple sidebars. This saves you from having to manually configure each copy of the widget and later having to worry about keeping them in sync should you ever need to make any changes. Particularly useful for those who define logic in their themes to conditionally include different versions of a sidebar depending on what template is being shown. Depending on use, it is an alternative to plugins that introduce in-widget logic to determine when widgets should be visible (Widget Logic, Section Widget, Conditional Widgets, etc).
Quick overview of what this plugin does:

Adds a widget called “Duplicate”. The widget’s only setting is a dropdown listing all active widgets. The selected widget will be the widget duplicated by the duplicate widget.
A duplicate widget shows the same title and content as its source widget, even if those values later get changed in the source widget.
A widget can be duplicated any number of times and can appear multiple times within the same page. (Yes, even within the same sidebar, though why would you do that?)
A duplicate widget will abide by the configuration of the sidebar it is placed in, not the configuration of the sidebar containing the source widget. So it uses ‘before_widget’, ‘after_widget’, ‘before_title’, ‘after_title’ values of its own sidebar.
Widgets that are duplicated will have “[D]” prepended to their name in the widget titlebar in the admin to denote they have duplicates. Also, at the bottom of the widget’s configuration form (when the widget is expanded), a short blurb also explains that the widget has duplicate(s) and a count of how many duplicates it has.
If a widget is deactivated or deleted, if it has any duplicates, they get deleted as well.
The widget id and widget type of the source widget are included as HTML classes in the duplicate widget’s markup.

Links: Plugin Homepage | Plugin Directory Page | Author Homepage
Filters
The plugin exposes four actions for hooking. Typically, customizations utilizing these hooks would be put into your active theme’s functions.php file, or used by another plugin.
c2c_before_duplicate_widget (action)
The ‘c2c_before_duplicate_widget’ hook allows you to output text, or perform some sort of action, just before the output of the duplicate widget.
Arguments:

$instance (array) : The settings for the widget instance (namely: title and widget_to_duplicate)
$args (array) : The configuration for the widget and sidebar

Example:
// Output an opening

before duplicate widget content
add_action( 'c2c_before_duplicate_widget', 'my_c2c_before_duplicate_widget', 10, 2 );
function my_c2c_before_duplicate_widget( $instance, $args ) {
echo '

;
}

c2c_after_duplicate_widget (action)
The ‘c2c_after_duplicate_widget’ hook allows you to output text, or perform some sort of action, just after the output of the duplicate widget.
Arguments:

$instance (array) : The settings for the widget instance (namely: title and widget_to_duplicate)
$args (array) : The configuration for the widget and sidebar

Example:
// Output an closing

after duplicate widget content
add_action( 'c2c_after_duplicate_widget', 'my_c2c_after_duplicate_widget', 10, 2 );
function my_c2c_after_duplicate_widget( $instance, $args ) {
echo '

;
}

c2c_before_duplicate_widget_form (action)
The ‘c2c_before_duplicate_widget_form’ hook allows you to output text, or perform some sort of action, just before the output of the duplicate widget’s configuration form (in the WP admin).
Arguments:

$instance (array) : The settings for the widget instance (namely: title and widget_to_duplicate)

Example:
// Display a message just before the duplicate widget settings form
add_action( 'c2c_before_duplicate_widget_form', 'my_c2c_before_duplicate_widget_form' );
function my_c2c_before_duplicate_widget_form( $instance ) {
echo '

Note: this is a note above the widget settings form.

';
}

c2c_after_duplicate_widget_form (action)
The ‘c2c_after_duplicate_widget_form’ hook allows you to output text, or perform some sort of action, just after the output of the duplicate widget’s configuration form (in the WP admin).
Arguments:

$instance (array) : The settings for the widget instance (namely: title and widget_to_duplicate)

Example:
// Display a message just after the duplicate widget settings form
add_action( 'c2c_after_duplicate_widget_form', 'my_c2c_after_duplicate_widget_form' );
function my_c2c_after_duplicate_widget_form( $instance ) {
echo '

Note: this is a note below the widget settings form.

';
}

延伸相關外掛

文章
Filter
Apply Filters
Mastodon