我一直在嘗試使用樹枝渲染單頁模板,但到目前爲止一切都失敗了。如何使用樹枝渲染單頁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>
對應的功能:
$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);
真的很感謝任何幫助解決這個問題。
它看起來並不像你分享了負責輸出頁面標題的模板代碼... – rnevius
@rnevius我添加了一個呈現的模板 – Bazinga777
您是否嘗試過使用'wp.title'? – rnevius