【问题标题】:How To Add a Class To a Custom Sidebar in WordPress如何在 WordPress 中将类添加到自定义侧边栏
【发布时间】:2017-06-29 12:40:52
【问题描述】:

我刚刚学会了如何创建自定义 WordPress 主题。我想为我的侧边栏分配一个类以进行样式设置,但我没有在网上找到任何解释如何执行此操作的内容。我添加到我的functions.php文件以注册我的侧边栏的代码是:

if ( function_exists('register_sidebar') ) register_sidebar(数组( 'id' => 'sidebar-1', 'description' => __('在此处添加小部件以显示在您的侧边栏中。', 'twentysixteen' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ));

我添加到 sidebar.php 文件中的代码是:

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

任何帮助将不胜感激!

【问题讨论】:

    标签: php css wordpress


    【解决方案1】:

    使用 before_widget 和 after_widget 添加包装器。

    【讨论】:

      【解决方案2】:
      register_sidebar( array(
              'name'          => esc_html__( 'Sidebar', 'twentysixteen' ),
              'id'            => 'sidebar-1',
              'description'   => 'Add widgets here to appear in your sidebar.',
              'before_widget' => '<aside id="%1$s" class="widget custom-class %2$s">',
              'after_widget'  => '</aside>',
              'before_title'  => '<h2 class="widget-title custom-class">',
              'after_title'   => '</h2>',
          ) );
      

      在functions.php文件中试试这个

      【讨论】:

        猜你喜欢
        • 2023-03-26
        • 1970-01-01
        • 2023-03-22
        • 1970-01-01
        • 2013-11-24
        • 2017-09-09
        • 2017-11-15
        • 1970-01-01
        • 2012-12-23
        相关资源
        最近更新 更多