创建自定义侧边栏wordpress

时间:2017-05-12 07:56:05

标签: wordpress sidebar

我想为我的wordpress网站创建自定义右侧边栏。

像这个wordpress_right_sidebar

这样的东西

enter image description here

  1. 应该是完全负责任的。
  2. 我要发布更多项目。
  3. 我需要什么东西?

1 个答案:

答案 0 :(得分:1)

将此代码添加到functions.php中以注册自定义侧边栏:

function my_custom_sidebar() {
    register_sidebar(
        array (
            'name' => __( 'Custom', 'your-theme-domain' ),
            'id' => 'custom-side-bar',
            'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
            'before_widget' => '<div class="widget-content">',
            'after_widget' => "</div>",
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        )
    );
}
add_action( 'widgets_init', 'my_custom_sidebar' );

我想仅在单个帖子中呈现自定义侧边栏,因此我将编辑&#34;单个帖子&#34;文件在single.php

<?php if ( is_active_sidebar( 'custom-side-bar' ) ) : ?>
    <?php dynamic_sidebar( 'custom-side-bar' ); ?>
<?php endif; ?>
  • 转到外观&gt;用于查看新侧边栏是否可用的小部件。
  • 添加您需要的小部件。 enter image description here
相关问题