我一直在尝试使用 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>
对应的功能:
$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);
非常感谢任何有关解决此问题的帮助。
最佳答案
不确定我的问题是否正确,但引用 a similar issue
On my single post page, I was using the_title instead of single_post_title.
所以尝试改变
<h2 class="section-heading">{{ wp.the_title }}</h2>
到
<h2 class="section-heading">{{ wp.single_post_title }}</h2>
另见相关:
关于php - 如何使用 twig 呈现单页 wordpress 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32767410/