dongyilai4214 2013-12-10 12:52
浏览 131
已采纳

窗口小部件没有出现在wordpress的主页侧边栏中

I have added some widgets to my homepage sidebar, but they are not appearing on the home page. If I add some widgets to the main sidebar it will appear in home page, and other pages.

I am new to Wordpress, I don't know how to solve this issue, and also default widgets are not appearing. I am using wp-bootstrap theme and a Q/A paid plugin.

  • 写回答

1条回答 默认 最新

  • dqdtgiw4736 2013-12-10 13:02
    关注

    First of all register your homepage sidebar in function.php

    function Name_widgets_init() {
        register_sidebar(array(
            'name' =>   __( 'homepage sidebar', 'test theme' ),
            'id' =>     'sidebar_homepage',
            'description' => __( 'This Wwill appear on homepage sidebar', 'test theme' )
        ) );
    } 
    add_action( 'widgets_init', 'Name_widgets_init' );
    

    Than use this trick to display your widgets, put the following code to the home page where you want to add sidebar

    <div class="sidebar_home" id="sidebar_left">
    
    <?php if ( is_active_sidebar( 'sidebar-left' ) ) : ?>
            <div id="secondary" class="widget-area" role="complementary">
                <?php dynamic_sidebar( 'sidebar_homepage' ); ?>
            </div>
        <?php endif; ?>
    
    </div>
    

    Finally Note i have used a div in last chunk of code please write your own CSS to control it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法