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 :
<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 page
Would really appreciate any help on fixing this.
Not sure if I got your question right but quoting a similar issue
On my single post page, I was using the_title instead of single_post_title.
So try changing
<h2 class="section-heading">{{ wp.the_title }}</h2>
to
<h2 class="section-heading">{{ wp.single_post_title }}</h2>
Also, see related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With