admin管理员组文章数量:1122832
I want to display a widget outside the sidebar, but I can't get my code to work.
The theme name is radius-primary-sidebar
and my widget id is text-20
(according to the html in the admin page. See image #1).
I've tried using the_widget("radius-primary-sidebar", "widget-id=text-20")
, but that didn't return anything.
What I'm I doing wrong?
I'm using wordpress 3.5.2
.
From /wp-admin/widgets.php
in the admin panel.
I want to display a widget outside the sidebar, but I can't get my code to work.
The theme name is radius-primary-sidebar
and my widget id is text-20
(according to the html in the admin page. See image #1).
I've tried using the_widget("radius-primary-sidebar", "widget-id=text-20")
, but that didn't return anything.
What I'm I doing wrong?
I'm using wordpress 3.5.2
.
From /wp-admin/widgets.php
in the admin panel.
- Where exactly outside the sidebar? You're referring to a native widget where the i.d changes each time you use a different text widget. I assume you want to create a new widget area? – Brad Dalton Commented Apr 17, 2014 at 11:50
- I want to display a single widget in the bottom of my mobile site. – Linus Oleander Commented Apr 17, 2014 at 11:56
- How are you generating your mobile site? – Brad Dalton Commented Apr 17, 2014 at 12:06
3 Answers
Reset to default 0According to the codex, the first argument should be a valid widget class name and not the theme name.
<?php the_widget( 'Replace_With_Valid_Widget_Class_Name', 'widget-id=text-20' ); ?>
This is how you add a widget from your functions file.
Note: Only displays on mobiles.
//functions.php
function wpsites_register_widget() {
register_sidebar( array(
'name' => 'Bottom Widget',
'id' => 'bottom-widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
}
add_action( 'widgets_init', 'wpsites_register_widget' );
add_filter( 'loop_end', 'bottom_widget', 25 );
function bottom_widget() {
if ( wp_is_mobile() && is_active_sidebar( 'bottom-widget' ) ) {
dynamic_sidebar('bottom-widget', array(
'before' => '<div class="bottom-widget">',
'after' => '</div>',
) );
}
}
You can change the loop_start hook to loop_end or use any other WordPress or theme specific hook.
You can also add the widget in a template file like single.php
<?php if ( wp_is_mobile() && is_active_sidebar( 'bottom-widget' ) ) : ?>
<ul id="bottom-widget">
<?php dynamic_sidebar( 'bottom-widget' ); ?>
</ul>
<?php endif; ?>
Uses wp_is_mobile()
to check if browser being used on a mobile device.
You should use CSS Media Queries to style your widget for display on different sized mobile devices.
Please Try with bellow inside functions.php
function wpsites_register_widget() {
register_sidebar( array(
'name' => 'Bottom Widget',
'id' => 'bottom-widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
Copy the code and pastest as you want to show the widgets
if (is_active_sidebar( 'bottom-widget' ) ) :
dynamic_sidebar( 'bottom-widget' );
endif;
本文标签: Display widget outside sidebar
版权声明:本文标题:Display widget outside sidebar? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294857a1929447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论