【问题标题】:Wordpress sidebar not visibleWordpress 侧边栏不可见
【发布时间】:2016-08-17 03:02:10
【问题描述】:

在我的footer.php 中,我添加了<?php get_sidebar('lj_sidebar'); ?> 在我的functions.php 中,我启用了小部件:add_theme_support('widgets'); 并制作了一个动作挂钩add_action('widgets_init', 'lj_widgets');

然后在我的widgets.php 中制作这样的小部件:

<?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>'
    ));
}

在我的sidebar.php 中,我检查侧边栏是否已启用:

<?php

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

小部件在我的管理面板中可见。但是当我在其中放置一个文本字段时。不显示?

我在这里做错了什么?

【问题讨论】:

  • 这段代码没有问题。它对我来说工作正常。我们需要更多细节。
  • 您可以使用此代码调用侧边栏中的小部件 if(is_active_sidebar('lj_sidebar')) { dynamic_sidebar('lj_sidebar'); }

标签: php wordpress


【解决方案1】:

当您调用 get_sidebar( 'lj_sidebar' ); 时,WordPress 正在寻找文件 sidebar-lj_sidebar.php 而不是 sidebar.php

您使用dynamic_sidebar( 'lj_sidebar' ); 正确调用了侧边栏,上面写着“显示ID 为lj_sidebar 的小部件区域”,但它没有显示在前端,因为您告诉WordPress 显示@ 的内容987654326@ 大概不存在。

要么:

  1. 将您的 sidebar.php 重命名为 sidebar-lj_sidebar.php,或
  2. 将侧边栏呼叫从 get_sidebar( 'lj_sidebar' ); 更改为 get_sidebar();

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 2022-12-10
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多