首页 > 解决方案 > 难以在 wordpress single.php 中显示动态侧边栏

问题描述

我试图在我的 single.php 中显示侧边栏小部件但我不确定发生了什么。它在页面加载时显示并消失,然后显示数字“1”而不是小部件形式。

这是function.php中的代码

function wpb_widgets_init() {

    register_sidebar( array(
        'name' => __( 'Subscribe form sidebar', 'semplice' ),
        'id' => 'newsletter',
        'description' => __( 'The subscribe form sidebar appears on the right on each post', 'semplice' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );
    }

add_action( 'widgets_init', 'wpb_widgets_init' );

single.php 中的代码

$output .= '
                <div class="container">
                    <div class="row">
                        <div class="column" data-xl-width="8" data-md-width="11" data-sm-width="12" data-xs-width="12">
                            <div class="post-heading">
                                ' . $this->date_comments_link($id, $options, $permalink) . '
                                <h2><a href="' . $permalink . '">' . get_the_title() . '</a></h2>
                            </div>
                            <div class="post-content">
                                ' . $this->get_content($is_single) . '
                                ' . $this->metas($id, $options) . '
                            </div>
                        </div>
    
                        <div class="column" data-xl-width="4" data-md-width="11" data-sm-width="12" data-xs-width="12">
                            ' . dynamic_sidebar( 'newsletter' ) . '
                        </div>
    
                    </div>
                </div>
            ';
    
            return $output;
        }

请有人纠正这里的错误是什么?

提前致谢。

标签: phpwordpress

解决方案


推荐阅读