如何用树枝渲染单页wordpress模板

Baz*_*777 20 php wordpress wordpress-theming 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 %}
Run Code Online (Sandbox Code Playgroud)

其中一个模板看起来像:

<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>
Run Code Online (Sandbox Code Playgroud)

相应的功能:

        $wpgetpages = new Twig_SimpleFunction("pages", function() { 

                $currentID = get_the_ID();

                $menu_order = wp_get_nav_menu_items('header');

                $menu_items = array();

                foreach($menu_order as $item) {

                    $menu_items[] = $item->ID;
                }

                $args = array('post_type' => 'page',
                              'status' => 'publish',                                  
                              'exclude'=> $currentID,
                              'orderby' => 'menu_order',                                  
                              'order' => 'ASC'
                           );

                $pages = get_posts($args);

                return $pages;

        });     

        $wpsetpages = new Twig_SimpleFunction("set_up_page", function($arg) {   

                setup_postdata($arg);                       

        });

        self::$twig_environment->addFunction($wpposts);
        self::$twig_environment->addFunction($get_theme_options);
        self::$twig_environment->addFunction($wppostdata);          
        self::$twig_environment->addFunction($wpgetpages);
        self::$twig_environment->addFunction($wpsetpages);  
Run Code Online (Sandbox Code Playgroud)

这会显示模板,但它会将模板中的页面标题设置为主页的标题在此输入图像描述

非常感谢任何帮助解决这个问题.

sit*_*lge 1

不确定我的问题是否正确,但引用了类似的问题

在我的单个帖子页面上,我使用的是 the_title 而不是 single_post_title。

所以尝试改变

<h2 class="section-heading">{{ wp.the_title }}</h2>
Run Code Online (Sandbox Code Playgroud)

<h2 class="section-heading">{{ wp.single_post_title }}</h2>
Run Code Online (Sandbox Code Playgroud)

另请参阅相关: