use*_*021 2 wordpress sidebar dynamic
我已经在wordpress支持上发布了这个,但这里的答案要快得多......
这是一个'复制粘贴':
我想在home.php模板上添加额外的小部件区域.我正在使用Emil Uzelac的Responsive主题.我不知道为什么我的额外'侧边栏'不起作用.
dynamic_sidebar('front-side-sidebar');
Run Code Online (Sandbox Code Playgroud)
该函数返回true但不显示任何内容.我可以在"Widgets"中看到我的额外小部件区域,我确实在那里添加了一个小部件.在我的functions.php中我有这个:
function front_side_sidebar_init()
{
register_sidebar(
array(
'id' => 'front-side-sidebar',
'name'=>'Front Side sidebar',
'description' => __('Front Side sidebar', 'responsive'),
'before_widget' => '<li>',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
add_action( 'widgets_init', 'front_side_sidebar_init' );
Run Code Online (Sandbox Code Playgroud)
小智 5
我就是这样做的,我不知道这个主题是否能够在主题选项中创建新的侧边栏,所以这就是为什么我像我一样回答.
在Functions.php中添加此项
register_sidebar(array(
'name' => __( 'Front Side sidebar' ),
'id' => 'front-side-sidebar',
'description' => __( '' ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
Run Code Online (Sandbox Code Playgroud)
如果您设置了静态首页,则wordpress将使用front-page.php.如果你没有这个,它将使用page.php,我不懂英语,但在这里查看更多.这里!
在您的模板中(front-page.php或page.php home.php您正在使用的内容 )用此替换侧边栏区域()
<?php get_sidebar('front-page'); ?>
Run Code Online (Sandbox Code Playgroud)
此代码将查找文件sidebar-front-page.php,并在该文件中添加此代码.在模板目录中添加sidebar-front-page.php
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('front-side-sidebar')) : ?>(you can also put code here if you dont have anything in the this sidebar, it will show this function as standard if you dont have any thing on this sidebar.<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
简而言之,此代码将检查带有id'front-side-sidebar'的侧边栏,并显示您在侧边栏中设置的小部件.
是的,这应该工作!:)