2013-06-29 18 views
0

大家好我开发WordPress的主题我读了很多动态侧边栏,但他们没有工作,我的功能代码:WordPress的动态栏不行

<?php 
if (function_exists('dynamic_sidebar')) 
    register_sidebar(array(
     'before_widget' => '<div class="wcon">', 
     'after_widget' => '</div>', 
     'before_title' => '<h3>', 
     'after_title' => '</h3>', 
    )); 
?> 

和我的sidebar.php代码:

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

,我是歌厅的sidebar.php使用此代码:

<?php get_sidebar(); ?> 

这似乎是罚款,但我不能添加Wi dget它没有wordpress面板中的链接,也没有直接访问。

回答

1

在你的functions.php

添加此下方

//initialize addiional sidebars. 
    if(function_exists('register_sidebar')){ 
     register_sidebar(
      array(
       'name' => 'second-sidebar' , 
       'id' => 'second-sidebar', 
       'before_widget' => '<li class ="widget-container>"', 
       'after_widget' => '</li>', 
       'before_title' => '<h3 class="widget-title">', 
       'after_title' => '</h3>' 
      ) 
     );} 

越看越你希望它出现的位置,添加此

<?php dynamic_sidebar('second-sidebar'); ?> 

然后去你的WordPress后台,在小部件区域,你会看到在右手侧的“第二栏”选项卡。放在你的小部件,你应该很好去。

希望这有助于

0

试试这个:

的functions.php

add_action('widgets_init', 'my_register_sidebars'); 

function my_register_sidebars() { 

register_sidebar(
    array(
     'id' => 'primary', 
     'name' => __('Primary'), 
     'description' => __('Main Sidebar'), 
        'before_widget' => '<div class="wcon">', 
        'after_widget' => '</div>', 
        'before_title' => '<h3>', 
        'after_title' => '</h3>' 
    ) 
); 
} 

的sidebar.php

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) : ?> 
    <?php dynamic_sidebar('primary'); ?> 
<?php endif; ?> 
0

这里有一个简单的答案:

//栏php文件

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-name')) : ?> 
    <p>You're not using a dynamic sidebar</p> 
<?php endif; ?> 

//functions.php

if (function_exists('register_sidebar')) 
    register_sidebar(array(
    'name'=>'sidebar-name', 
    'before_widget' => '<div class="your-class">', 
    'after_widget' => '</div>', 
    'before_title' => '<h2>', //h3, h4, h5, whatever size header you prefer 
    'after_title' => '</h2>', 
));