2010-11-18 43 views
16

我迷路了一下。WordPress的 - 顯示特定的部件

比方說,我有一個朝氣蓬勃的footer-siderbar。目前爲止很簡單。

<footer> 
    <?php get_sidebar("name") ?> 
</footer> 

顯示在頁腳中。

但我們在這裏。我想在我的網格的每個插件:

 <footer> 
     <div style="width: 100px:"> 
      <div style="width: 25%">First widget here</div> 
      <div style="width: 25%">Second widget here<</div> 
      <div style="width: 25%">Third widget here<</div> 
      <div style="width: 25%">Fourth widget here<</div> 
      </div> 
     </footer> 

所以get_sidebar是不是一種選擇,現在,因爲它顯示所有部件在一排。我不想編輯小部件本身。

他們如何做到這一點在主題?

謝謝。

回答

15

您可以使用 'the_widget' 功能可實現此:

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

更多信息可以在Wordpress Codex - The_Widget reference找到。

+2

想法不錯,但據我所知the_widget需要插件的名稱作爲第一個參數,我不知道會是怎樣在頁腳小工具的名稱。我只有側欄名稱。 – fomicz 2010-11-18 12:48:43

+2

您是否設法使用the_widget來顯示現有的窗口小部件(而不是創建一個新窗口)?你是怎麼做到的? – NPC 2012-04-02 11:16:30

+1

你在實例和$ args中放入了什麼?你怎麼知道該放什麼。 – ahnbizcad 2016-03-25 02:22:36

2

這是一個很好的參考,以及 - Function Reference/dynamic sidebar « WordPress Codex

如果您使用頁面上的方法:

<ul id="sidebar"> 
<?php if (!dynamic_sidebar()) : ?> 
    <li>{static sidebar item 1}</li> 
    <li>{static sidebar item 2}</li> 
<?php endif; ?> 
</ul> 

然後,您可以使用CSS樣式跨頁腳側邊欄小工具的位置。

編輯以包括以下...

阿拉斯主題CSS:

#footer    { margin: 20px auto 0; width: 980px; background: #ECEBE6; padding-bottom: 10px; border: 1px solid #CCC; } 
#footer .widgetcontainer { padding: 5px 10px; min-width: 150px; } 
.no-js #footer .widgetcontainer { height: 190px; } 
#footer .widgettitle { background: none; border: none; font-size: 14px; color: #444; padding: 0 0 10px; letter-spacing: -1px; } 
#footer .widgetcontent { font-size: 12px; background: none; padding: 0; border: none; } 
#footer .footer-message { margin: 0; padding: 10px 15px 0; font-size: 11px; } 
#footer .footer-message p { margin: 0 0 0.5em; } 
#footer .footer-message .floatright { margin-left: 20px; } 
#footer-sidebar  { overflow: hidden; margin: 10px 10px 0; padding: 0 0 10px; border-bottom: 1px solid #CCC; } 
#footer-sidebar .widgetcontainer { float: left; margin: 0; max-width: 250px; } 
#footer-sidebar ul { list-style: none; margin: 0; padding: 0; } 
#footer-sidebar li { margin: 0 0 3px; } 

頁腳編碼:

<ul id="footer-sidebar" class="clearfix xoxo"> 
     <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer')) : ?> 
     <li></li> 
    <?php endif; ?> 
</ul> 

在主題的它,然後放置在整個部件這一頁。

+0

謝謝,現在已經挖了幾個小時Codex,但仍然沒有運氣。 – fomicz 2010-11-18 12:50:32

+0

請參閱上面的編輯,這可能會更有幫助。 – 2010-11-18 12:57:01

+0

另外,如果你看看阿拉斯主題,他們在頁腳上運行相同的想法 - http://demo.arrastheme.com/ – 2010-11-18 12:58:18

0

另外,您還可以使用:

<?php dynamic_sidebar('sidebar-1'); ?> 
0

可以使用的Widget插件的選項,限制或控制的任何網頁和設備的部件知名度;在存儲庫上免費提供:https://wordpress.org/plugins/widget-options/。或嘗試使用widget_display_callbackhttps://developer.wordpress.org/reference/hooks/widget_display_callback/。我希望這有幫助。

function custom_display_callback($instance, $widget, $args){ 
    if(is_page()){ 
     return false; 
    } 
    return $instance; 
} 
add_filter('widget_display_callback', 'custom_display_callback', 50, 3); 

enter image description here

相關問題