Wordpress - 显示特定的小部件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4214830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress - display specific widget
提问by fomicz
I'm lost a bit.
我有点失落。
Let's say I have a dynmic footer-siderbar. Easy so far.
假设我有一个动态的页脚边栏。到目前为止很容易。
<footer>
<?php get_sidebar("name") ?>
</footer>
Displys it in the footer.
在页脚中显示它。
But here we are. I want EACH widget inside of my grid:
但我们来了。我想要我的网格内的每个小部件:
<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>
So get_sidebar isn't an option now, since it displays all widgets in a row. And I don't want to edit widgets itself.
所以 get_sidebar 现在不是一个选项,因为它会连续显示所有小部件。而且我不想编辑小部件本身。
How they do that in themes?
他们如何在主题中做到这一点?
Thanks.
谢谢。
采纳答案by Rhapsody
You can use the 'the_widget' function for this:
您可以为此使用“the_widget”函数:
<?php the_widget($widget, $instance, $args); ?>
More information can be found on the Wordpress Codex - The_Widget reference.
更多信息可以在Wordpress Codex-The_Widget 参考中找到。
回答by Vince Pettit
This is a good reference as well - Function Reference/dynamic sidebar « WordPress Codex
这也是一个很好的参考 -函数参考/动态侧边栏« WordPress Codex
If you use the method on that page:
如果您使用该页面上的方法:
<ul id="sidebar">
<?php if ( !dynamic_sidebar() ) : ?>
<li>{static sidebar item 1}</li>
<li>{static sidebar item 2}</li>
<?php endif; ?>
</ul>
You could then use CSS styling to position the sidebar widgets across the footer.
然后,您可以使用 CSS 样式将侧边栏小部件定位在页脚上。
Edit to include the following...
编辑以包括以下内容...
Arras theme CSS:
Arras 主题 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; }
Footer coding:
页脚编码:
<ul id="footer-sidebar" class="clearfix xoxo">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer') ) : ?>
<li></li>
<?php endif; ?>
</ul>
In the theme it then places the widgets across the page.
然后在主题中将小部件放置在整个页面上。
回答by Globalz
Please checkout my new plugin that displays a specific widget.
请查看我显示特定小部件的新插件。
回答by Mahesh Budeti
Alternatively you can also use :
或者,您也可以使用:
<?php dynamic_sidebar( 'sidebar-1' ); ?>
回答by Jeffrey Carandang
You can use Widget Options Plugin to restrict or control the widgets visibility on any pages and devices; available for free on the repository : https://wordpress.org/plugins/widget-options/. Or try using widget_display_callback
https://developer.wordpress.org/reference/hooks/widget_display_callback/. I hope this helps.
您可以使用小部件选项插件来限制或控制小部件在任何页面和设备上的可见性;在存储库中免费提供:https: //wordpress.org/plugins/widget-options/。或者尝试使用widget_display_callback
https://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 );