douli2876 2016-04-23 13:28
浏览 108
已采纳

Wordpress侧边栏不可见

In my footer.php I've added <?php get_sidebar('lj_sidebar'); ?> In my functions.php I've enabled widgets: add_theme_support('widgets'); and made a action hook add_action('widgets_init', 'lj_widgets');

Then in my widgets.php I make the widget like this:

<?php

function lj_widgets() {
    register_sidebar(array(
        'name'          => __('My First Theme Footer','lnj'),
        'id'            => 'lj_sidebar',
        'description'   => __('Footer for my first theme','lnj'),
        'class'         => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>'
    ));
}

In my sidebar.php I check if the sidebar is enabled:

<?php

if(is_active_sidebar('lj_sidebar')) {
    dynamic_sidebar('lj_sidebar');
}

The widget is visible in my admin panel. But when I put for example a textfield in it. It's not showing up?

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • douluan4644 2016-04-23 15:28
    关注

    When you call get_sidebar( 'lj_sidebar' );, WordPress is looking for the file sidebar-lj_sidebar.php and not sidebar.php.

    You're calling your sidebar correctly with dynamic_sidebar( 'lj_sidebar' ); which says, "Display the widget area with the id lj_sidebar" but it's not displaying on the front-end because you're telling WordPresss to display the contents of sidebar-lj_sidebar.php which presumably doesn't exist.

    Either:

    1. Rename your sidebar.php to sidebar-lj_sidebar.php, or
    2. Change your sidebar call from get_sidebar( 'lj_sidebar' ); to get_sidebar();.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题