微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

木材/树枝 - 试图将侧边栏内容作为我的页脚的一部分

如何解决木材/树枝 - 试图将侧边栏内容作为我的页脚的一部分

我希望有更多使用木材经验的人可以帮助我?我正在尝试使用木材/树枝创建一个 wordpress 主题,我希望能够在网站内每个页面的页脚中包含 yelp 评论

我有以下文件

sidebar.twig

<!-- Review and contact button Section -->
{% if sidebar %}
    <section class="reviewSection">
        <div class="review__container">
            {{sidebar.text}}
        </div>
    </section>
{% endif %}

footer.twig

{% include('templates/_embeds/_sidebar.twig') %}
<!-- Footer -->
<footer>
    {# <div class="footer__contact">
        <div class="FooterCTABox">
            <a class="cta--contact FooterCTA"href="{{site.url.path}}/contact">Book Now</a>
            <a class="cta--phone FooterCTA"href="tel:080979767645">Call Us</a>
        </div>
    </div> #}
    <div class="footer__main">
        <div class="main__container">
            <div class="main__addressCol footerCol">
                <h4>Get in touch</h4>
                <div class="footerCol__content footerCol__content--address">
                    <p><span>1 Address Blvd<br />place<br />San Diego<br />Zipcode</span><br /><span class="address__contact"tel: <a href="">0880009123123</a></span><br /><span class="address__contact"email: <a href="">info@email.com</a></span></p>
                </div>
            </div>
            <div class="main__linkCol footerCol">
                <h4>Links</h4>
                <div class="footerCol__content">
                    <ul>
                        <a href="{{site.theme.path}}/faqs"><li>FAQS</li></a>
                        <a href="{{site.theme.path}}/blog"><li>Blog</li></a>
                        <a href="{{site.theme.path}}/gallery"><li>gallery</li></a>
                        <a href="{{site.theme.path}}/events"><li>Events</li></a>
                        <a href="{{site.theme.path}}/contact"><li>Contact</li></a>
                    </ul>
                </div>
            </div>
            <div class="main__socialCol footerCol">
                <h4>Follow us</h4>
                <div class="footerCol__content footerCol__content--social">
                    <ul>
                        <a href=""><li>Facebook</li></a>
                        <a href="<li>Instagram</li></a>
                        <a href=""><li>Yelp</li></a>
                    </ul>
                </div>
            </div>
            <div class="main__logoCol footerCol">
                <picture>
                    <img src="{{site.theme.path}}/images/logo-text-sm.png" alt="logo" />
                </picture>
          
            </div>
        </div>
    </div>
    <div class="footer__end">
        <div class="end__links">
            <ul>
                <li class="end__date">{{ "Now"|date("Y") }} &#169; {{ site.name }}</li>
                <a href="{{site.url}}/terms" class="end__links__link"><li>Terms &amp; Conditions</li></a>
                <li class="web">Website Designed &amp; managed by - <a href="#" class="end__links__link">Web Design</a></li>
            <ul>
        </div>
    </div>
</footer>
<script type="text/javascript" src="{{site.theme.path}}/scripts/script.js"></script>
</body>
</html>

sidebar.PHP

<?PHP
/* sidebar.PHP */
$context = array();
$context['sidebar'] = Timber::get_sidebar('Primary Sidebar');
Timber::render('/templates/_embeds/_sidebar.twig',$context);

sidebar.scss

.reviewSection {
    background-color: #fff;
    height: auto;
    min-height: 200px;
    @include flex(center,center,row);
    @media (max-width: $mobileScreen) {
        margin-top: 30px;
    }
    .review__container {
        margin: auto;
        width: 70%;
        height: 25%;
        min-height: 150px;
        background-color: #d32323; // to be removed once the actual yelp plugin is in there.
        @include flex(center,row);
        h3 {
            color: $textPrimary;
        }
        @media (max-width: $tabletScreen) {
            width: 90%;
            margin: 0;
        }
    }
}

wordpress 中,我创建了一个小部件,目前正在使用 Yelp 评论插件

我遇到的问题是,当我运行代码时,侧边栏 HTML 显示,但不是插件中的实际侧边栏内容。我只是得到一个没有内容的大红色占位符框。我还包括wordpress 本身的侧边栏屏幕截图,以防万一这很有用,而且我在那里做错了。

sidebar image example

非常感谢任何人的帮助。我已经尝试搜索了几天以获得答案,但我不确定出了什么问题。

非常感谢

解决方法

您不需要 sidebar.php(因为您已经通过 twig 加载了它)并且您需要将侧边栏内容全局加载到上下文中,以便在您需要时加载。

移动这一行:

$context['sidebar'] = Timber::get_sidebar('Primary Sidebar');

与此处的菜单相同:https://timber.github.io/docs/guides/menus/#setting-up-a-menu-globally


它们是其他方式,但我最喜欢顶部的一种。但是,如果您想查看多个选项,请查看 official documentation for sidebars

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。