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 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题