WordPress页脚小部件区域不显示内容

时间:2015-11-02 18:37:00

标签: php wordpress

我在a theme中添加了3个页脚小部件区域。我在小部件中添加了一些内容,但它没有在网站上显示。请指导。感谢。

functions.php中的代码

<?php
/**
 * Register our sidebars and widgetized areas.
 *
 */
function arphabet_widgets_init() {

    register_sidebar( array(
        'name'          => 'Footer sidebar 1',
        'id'            => 'footer_1',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>
<?php
/**
 * Register our sidebars and widgetized areas.
 *
 */
function arphabet_widgets_init2() {

    register_sidebar( array(
        'name'          => 'Footer sidebar 2',
        'id'            => 'footer_2',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init2' );
?>

<?php
/**
 * Register our sidebars and widgetized areas.
 *
 */
function arphabet_widgets_init3() {

    register_sidebar( array(
        'name'          => 'Footer sidebar 3',
        'id'            => 'footer_3',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init3' );
?>

footer.php中的代码:

<?php if ( is_active_sidebar( 'arphabet_widgets_init' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_1' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>
<?php if ( is_active_sidebar( 'arphabet_widgets_init2' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_2' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>
<?php if ( is_active_sidebar( 'arphabet_widgets_init3' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_3' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>

1 个答案:

答案 0 :(得分:2)

法赫德乌丁 在页脚中使用它:

<?php if ( is_active_sidebar( 'footer_1' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_1' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>
<?php if ( is_active_sidebar( 'footer_2' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_2' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>
<?php if ( is_active_sidebar( 'footer_3' ) ) : ?>
    <div >
        <?php dynamic_sidebar( 'footer_3' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>