提问者:小点点

Wordpress木材(细枝)-动态边栏


我是木材和TWIG的净资产。我无法让动态侧边栏显示出来。我的目标是内容只显示,如果有一个动态侧边栏,你在front-page.php.目前它告诉我,有小部件区,但我不在正确的页面上。然而,我相信front-page.php正在被渲染。我正在与木材启动主题(Github)为Wordpress作为基础。我可以让小部件显示,如果我直接添加代码,我在front-page.twig

侧边栏。php

#Timber::render( array( 'sidebar.twig' ), $data ); if i understand right, i can remove this?

$context = array();
$context['dynamic_sidebar'] = Timber::get_widgets('home_sidebar');
Timber::render('sidebar.twig', $context);

functions.php我在文件末尾添加了这个:

function custom_widgets_init() {

    register_sidebar( array(
        'id'          => 'home_sidebar',
        'name'        => __( 'Dynamic Sidebar 1', $text_domain ),
        'description' => __( 'This sidebar is located on the left side of the content.', $text_domain ),
    ) );
}
add_action( 'widgets_init', 'custom_widgets_init' );

字体页。细枝

{% extends "base.twig" %}

{# STUFF #}

{% block sidebar_area %}

        <aside>
            {{dynamic_sidebar}}
            {# {% do function('dynamic_sidebar', 'dynamic-sidebar-1') %} THIS HOWEVER WORKS #}
        </aside>

{% endblock %}

sidebar.twig:目前是空的


共1个答案

匿名用户

@frizzant:如果你还没有看过我们为侧边栏准备的指南:

https://timber.github.io/docs/guides/sidebars/