Я бы хотел иметь возможность переходить к предыдущим и следующим сообщениям в Timber с помощью специального запроса.У меня есть пост типа «проекты», показывающий «избранные проекты» на моей домашней странице.Как только я нажму на один из «проектов», я бы хотел перейти к предыдущему или следующему сообщению на основе того же запроса.Но в настоящее время результаты показывают все"проекты, а не результаты запроса. Я использую вариант single.twig для моего шаблона:
single-projects.php
$context = Timber::context();
$args = array(
'numberposts' => -1,
'post_type' => 'projects',
'meta_key' => 'featured',
'meta_value' => 1,
'order' => 'ASC',
'orderby' => 'order_clause',
'meta_query' => array(
'order_clause' => array(
'key' => 'order_number',
'type' => 'NUMERIC' // unless the field is not a number
)
)
);
$post = Timber::get_posts($args);
$context['projects'] = $post;
$timber_post = Timber::query_post();
$context['post'] = $timber_post;
Timber::render( 'single-projects.twig', $context );
шаблоны> single-projects.twig
{% if post.prev %}
<a href="{{ post.prev.link }}">Previous Project</a>
{% endif %}
{% if post.next %}
<a href="{{ post.next.link }}">Next Project</a>
{% endif %}
functions.php
Я попытался поместить запрос в functions.php, а также page-home.php, но это упрощенная версия того, что у меня есть:
public function add_to_context( $context ) {
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$project_args = array(
'numberposts' => 2,
'post_type' => 'projects',
);
$context['projects'] = Timber::get_posts($project_args);
return $context;
}
views> page-home.веточка
{% for post in projects %}
{{post.title}}
{% endfor %}