Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用twig呈现单页wordpress模板_Php_Wordpress_Twig_Wordpress Theming - Fatal编程技术网

Php 如何使用twig呈现单页wordpress模板

Php 如何使用twig呈现单页wordpress模板,php,wordpress,twig,wordpress-theming,Php,Wordpress,Twig,Wordpress Theming,我一直试图用Twig呈现一个单页wordpress模板,但到目前为止一切都失败了 {% extends 'layouts/base.twig' %} {% block content %} {% for page in pages() %}{{ set_up_page(page) }} {% include 'content/content-' ~ page.post_name ~ '.twig' %}

我一直试图用Twig呈现一个单页wordpress模板,但到目前为止一切都失败了

{% extends 'layouts/base.twig' %}

{% block content %} 
    {% for page in pages() %}{{ set_up_page(page) }}                                
        {% include 'content/content-' ~ page.post_name ~ '.twig' %}
    {% endfor %}
{% endblock %}
其中一个模板的外观:

<section id="about" {{ wp.post_class }}>
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2 class="section-heading">{{ wp.the_title }}</h2>
                <h3 class="section-subheading text-muted">{{ wp.get_post_meta(wp.get_the_ID() , 'st_page_subtitle', true)  }}</h3> <!-- To be Changed to subtext for title  -->
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
             {{ wp.the_content }}
            </div>
        </div>
    </div>
这会显示模板,但会将模板中的页面标题设置为主页标题


如果您能帮我解决这个问题,我将不胜感激。

我不确定您的问题是否正确,但请引用

在我的单篇文章页面上,我使用的是标题而不是单篇文章标题

所以试着改变

<h2 class="section-heading">{{ wp.the_title }}</h2>
{{wp.the_title}

{{wp.single_post_title}
另请参见相关的:

  • -使用外部环路
  • -使用内部循环

    • 你的问题有点不清楚。但是,如果您的主要问题是在这个页面中呈现的所有单个页面都有标题“HOME”,那么应该这样做

      尝试更改此选项:

      <h2 class="section-heading">{{ wp.the_title }}</h2>
      
      {{wp.the_title}
      
      为此:

      <h2 class="section-heading">{{ wp.get_post_meta(wp.get_the_ID() , 'title', true) }}</h2>
      
      {{wp.get_post_meta(wp.get_the_ID(),'title',true)}
      

      如果它适用于副标题,它也适用于标题。

      如果你试图在WordPress主题中使用细枝,我强烈建议安装一个名为Timber的插件。它为您处理了许多复杂的特定于WordPress的集成。他们有一个入门主题,您可以查看以更好地了解如何将主题组合在一起:


      他们还有全面的文档,您可以在这里找到:

      看起来您没有共享负责输出页面标题的模板代码…@rnevius我添加了一个呈现的模板您是否尝试过简单地使用
      wp.title
      ?@Bazinga777您能提供(或强调)给我们吗保存用于设置标题的代码的代码段?@sitilge the wp.the_title是wordpress the_title方法的代理。奇怪的是,页面的内容被正确显示,但标题却没有显示出来。我正在使用下面的主题框架,这正是我的问题所在,但是我已经为相同的主题框架获取了\u ID(),它返回了当前页面的ID,即主页。这就是让我困惑的地方。你用的是什么WP版本?我将尝试在4.3.1版本的dev box.Im中重新创建错误,下面是主题本身的链接
      <h2 class="section-heading">{{ wp.the_title }}</h2>
      
      <h2 class="section-heading">{{ wp.get_post_meta(wp.get_the_ID() , 'title', true) }}</h2>