【问题标题】:WordPress multiple sidebar is not workingWordPress 多个侧边栏不起作用
【发布时间】:2021-09-15 06:17:21
【问题描述】:

我可能会犯一个愚蠢的错误。我在一个函数调用中添加了两个侧边栏。但是,它显示了第一个侧边栏,但没有显示第二个侧边栏。想不通,问题到底出在哪里。我这里用的是register_sidebar函数。

functions.php

    function scilibrary_widgets_init() {
    register_sidebar( array (
        'name' => 'About Us Sidebar Gutech',
        'id' => 'about_sidebar_gutech'
    )
    );

    register_sidebar( array (
        'name' => 'Services Sidebar Gutech',
        'id' => 'services_sidebar_gutech'
    )
   );


   }

   add_action('widgets_init', 'scilibrary_widgets_init');

我的首页代码:

                             <div id="sidebar-primary-2" class="gutech-sidebar">
                                <?php if ( is_active_sidebar( 'services_sidebar_gutech' ) ) : ?>
                                    <?php 
                                    dynamic_sidebar( 'services_sidebar_gutech' ); ?>
                                <?php else : ?>
                                    <!-- Time to add some widgets! -->
                                    <p> Widget is missing </p>
                                <?php endif; ?>
                            </div>

你能看到我做的任何错误,你能帮我弄清楚吗? 谢谢。

【问题讨论】:

  • 您只调用了第一个侧边栏。您也必须调用第二个侧边栏。
  • @MartinMirchev 嗨,是的,它现在在我身边也能正常工作。奇怪的。昨晚和今天早上,它没有工作。工作中。哈哈。谢谢。无论如何,我的方法好吗?我没有在侧边栏中添加小部件之前、小部件之后等。可以吗?
  • 如果您对默认设置没问题,这不是问题。出于 SEO 目的,有时我会更改标题 h 标签。

标签: wordpress wordpress-theming


【解决方案1】:

我不确定你为什么要在一个容器中放置 2 个侧边栏,但你应该这样做

//Call first sidebar
if ( is_active_sidebar( 'about_sidebar_gutech' ) ) :
    dynamic_sidebar( 'about_sidebar_gutech' );
else :
    echo 'no sidebar';
endif; 
//Call second sidebar
if ( is_active_sidebar( 'services_sidebar_gutech' ) ) :
    dynamic_sidebar( 'services_sidebar_gutech' );
else :
    echo 'no sidebar';
endif; 

【讨论】:

  • 嗨@MartinMirchev,实际上我有两个不同的模板来使用两个不同的侧边栏。这就是创建两个侧边栏的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-17
  • 2020-05-27
  • 1970-01-01
  • 2022-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多