2011-06-15 49 views
0

我有一个functions.php文件,我注册了所有的侧边栏。当我打电话给一个侧栏时,会出现多个侧边栏。怎么修?

在的sidebar.php文件,我有这个

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Home Page')) : ?> 
<?php endif; ?> 

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Blog Page')) : ?> 
<?php endif; ?> 

然后我把它叫做

<?php get_sidebar('Home Page'); ?> 

然而博客页面侧边栏也显示了。该怎么办?

编辑: 等我需要为我所有的侧边栏创建一个页面吗?这就是为什么它不起作用?

这将是很多页面有没有其他方法呢?

回答

0

我做到这一点稍有不同,我做的:

这在我的functions.php:

// header 
    register_sidebar(array (
    'name' => 'Header Widget Area', 
    'id' => 'header_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>', 
    )); 

    // Single Post Sidebar 
    register_sidebar(array (
    'name' => 'Single Widget Area', 
    'id' => 'single_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>', 
)); 

然后我打电话给他们,像这样在不断模板我使用它们:

<?php if (is_sidebar_active('header_widget_area')) : ?> 
     <?php dynamic_sidebar('header_widget_area'); ?> 
<?php endif; ?> 

让我知道你是否需要更多帮助。

0

dynamic_sidebar()命令实际输出指定的侧边栏。当您调用get_sidebar时,它会显示这两个边栏,因为在条件中会输出边栏。

你不是很想找到你想要的东西。

你会想只需

get_sidebar(); 
在模板

然后在sidebar.php文件中,您将执行条件来确定何时显示什么。例如,这样的事情...

if (is_page()) : 
    dynamic_sidebar('page-sidebar'); 
elseif (is_post()) : 
    dynamic_sidebar('post-sidebar'); 
endif; 

让我知道如果你仍然有问题,我可以提供更多的细节/更好的更详细的解决方案例如