how to render a single page wordpress template with twig

I’ve been trying to render a single page wordpress template with Twig, but so far everything has failed.

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

{% block content %} 
    {% for page in pages() %}{{ set_up_page(page) }}                                
        {% include 'content/content-' ~ page.post_name ~ '.twig' %}
    {% endfor %}
{% endblock %}

What one of the templates looks like :

Read More
<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>

The corresponding functions :

        $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);  

This brings out the templates but it sets the page title from the template as the title of the home pageenter image description here

Would really appreciate any help on fixing this.

Related posts

3 comments

  1. You question is a little bit unclear. But if your main problem is that all single pages rendered in this single page have the heading “HOME” this should do it.

    Try changing this:

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

    to this:

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

    If it works for the subheading it should work for the title too.

Comments are closed.