[英]Why in my WordPress custom theme the widget area don't work? Widgets are not shown
[英]How can I specify that an area of my custom WordPress theme have to contains widgets\modules?
我是WordPress主题开发的新手,正在开发使用BootStra CSS框架的主题
我必须做的是,主题的特定区域可以包含一些小部件\\模块(我不知道WP中的正确名称是什么,我指的是后端设置的工具,该工具将某些组件输出为图库图像或幻灯片)
有人可以帮助我理解这一论点吗? 从什么可以开始执行此操作?
TNX
安德里亚
欢迎使用wordpress :)
因此,第一件事是注册小部件区域。 在您的functions.php
放置以下代码:
$args = array(
'name' => __( 'Sidebar name', 'theme_text_domain' ), // name that will show up in the admin
'id' => 'unique-sidebar-id',
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>' );
register_sidebar( $args );
有关参考,请参见官方法典页面
接下来,调用dynamic_sidebar()
函数,使内容显示在网站上,通常是sidebar.php
<?php if ( is_active_sidebar( 'unique-sidebar-id' ) ) : ?> //display widget area only if there are widgets asigned in the admin
<ul id="sidebar">
<?php dynamic_sidebar( 'unique-sidebar-id' ); ?>
</ul>
<?php endif; ?>
我希望这会帮助您入门。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.