Timber是否支持Pingbacks和Trackbacks?在文档中找不到。
需要这样的东西:
{% for ping in post.pings %}
{% include 'partials/pingback.twig' with { ping: ping } %}
{% endfor %}
答案 0 :(得分:0)
这是解决方案:
single.php
<?php
/**
* The Template for displaying Singe Post.
*/
$context = Timber::get_context();
$post = Timber::query_post();
$type = $post->post_type;
$protected = post_password_required($post->ID);
$context['post'] = $post;
$context['post']->pings = get_comments([
'post_id' => $post->ID,
'type' => 'pings',
'order' => 'ASC'
]);
if ($protected) {
Timber::render('single-password.twig', $context);
} else {
Timber::render([
'single-' . $post->ID . '.twig',
'single-' . $type . '.twig',
'single.twig',
], $context);
}
single.twig
{% if post.pings %}
<div class="card">
<h3 class="heading-1 mb-2">
{{ post.pings|length }} {{ __('Pingbacks and Trackbacks', textdomain) }}
</h3>
<div class="pingbacks">
{% for ping in post.pings %}
<div class="pingbacks__item">
{{ __('Pingback:', textdomain) }} <a href="{{ ping.comment_author_url }}" targer="_blank">{{ ping.comment_author }}</a>
</div>
{% endfor %}
</div>
</div>
{% endif %}