2011-06-15 48 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; 

讓我知道如果你仍然有問題,我可以提供更多的細節/更好的更詳細的解決方案例如