【问题标题】:Issue with Timber custom page template for Home page in WordPressWordPress 主页的 Timber 自定义页面模板问题
【发布时间】:2020-06-13 15:17:47
【问题描述】:

我在 Timber 模板的视图文件夹中创建了page-home-page.twig。然而,

1-如果页面home-page设置为默认wordpresshome-page,模板文件将不起作用。

2- 如果页面home-page设置为普通页面内容,那么现在模板就可以了。

谁能告诉我问题出在哪里?

请查看木材documentation

谢谢你, 塔里克

【问题讨论】:

    标签: wordpress templates timber website-homepage


    【解决方案1】:

    由于某种原因,我无法在任何地方找到可行的解决方案。然而,

    我找到了一个解决方法,如果遇到同样的问题,我希望它可以帮助其他人。

    我将其修复如下:

    1- 在我的 wordpress 主题文件夹 /wp-content/themes/my-theme/ 我创建了一个 自定义页面模板 参考本指南:Custom Page Templates

    使用此代码:

    <?php
    /**
     * Template Name: Video Template
     * Description: A Page Template for Home page Video CMS.
     */
    
    defined('ABSPATH') or die;
    use Timber\Timber;    
    $gantry = Gantry\Framework\Gantry::instance();
    $theme  = $gantry['theme'];
    
    // We need to render contents of <head> before plugin content gets added.
    $context              = Timber::get_context();
    $context['page_head'] = $theme->render('partials/page_head.html.twig', $context);
    $post                 = Timber::query_post();
    $context['post']      = $post;
    Timber::render(['page-' . $post->post_name . '.html.twig', 'page-hvideo.twig'], $context);
    

    Timber::render(['page-' . $post-&gt;post_name . '.html.twig', 'page-hvideo.twig'], $context); 将我们指向 主题/视图文件夹 下的新 Timber page-hvideo.twig 文件。

    2- 在我的 Timber 模板视图文件夹中,我添加了这个文件 page-hvideo.twig,代码如下:

    {% extends "partials/page.html.twig" %}
    {% set twigTemplate = 'single.html.twig' %}
    {% set scope = 'single' %}
    {% block content %}
        <div class="platform-content">
            <div class="content-wrapper">
                <section class="entry">
                    {% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %}
                </section>
            </div> <!-- /content-wrapper -->
        </div>
    {% endblock %}
    

    Where {% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %} 将照常管理Timber主题文件夹下view/partials文件夹中的主页自定义模板。

    我希望这对其他人有帮助。

    非常感谢您在这里提供的一切。

    已编辑: 请确保在添加主页自定义页面模板后,从 Page Attributes 部分下的 WordPress 帖子编辑屏幕中选择它。

    【讨论】:

      猜你喜欢
      • 2014-10-12
      • 2019-01-24
      • 2023-03-03
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      相关资源
      最近更新 更多