我无法在我的网站上显示侧栏。我添加了一个小部件部分,因为没有:function.php
<?php
if (function_exists(\'register_sidebar\'))
// Area 1
register_sidebar( array (
\'name\' => \'Primary Widget Area\',
\'id\' => \'primary_widget_area\',
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => "</li>",
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
// Area 2
register_sidebar( array (
\'name\' => \'Secondary Widget Area\',
\'id\' => \'secondary_widget_area\',
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => "</li>",
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
// Footer
register_sidebar( array (
\'name\' => \'Footer\',
\'id\' => \'footer_widget_area\',
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => "</li>",
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
?>
sidebar.php
<?php dynamic_sidebar( \'sidebar-3\' ); ?>
我将学习本教程:
WordPress Widgets Tutorial我尝试了许多在线示例,以下是两个:
wordpress custom modules/widget areas on the page? can i make my own? 和
Widgetizing Themes
最合适的回答,由SO网友:Hasibur Rahman 整理而成
您已经创建了三个侧栏primary_widget_area
, secondary_widget_area
, footer_widget_area
但在侧栏中,您可以调用不同的侧栏名称sidebar-3
; 这就是为什么没有显示侧边栏。
在侧栏中尝试以下代码。php:
// To display primary_widget_area sidebar
<?php if ( is_active_sidebar( \'primary_widget_area\' ) ) : ?>
<?php dynamic_sidebar( \'primary_widget_area\' ); ?>
<?php endif; ?>
// To display secondary_widget_areasidebar
<?php if ( is_active_sidebar( \'secondary_widget_area\' ) ) : ?>
<?php dynamic_sidebar( \'secondary_widget_area\' ); ?>
<?php endif; ?>
// To display footer_widget_areasidebar
<?php if ( is_active_sidebar( \'footer_widget_area\' ) ) : ?>
<?php dynamic_sidebar( \'footer_widget_area\' ); ?>
<?php endif; ?>
谢谢大家!