Timber Twig 模板 - sticky post 不仅推到列表顶部,它还为页面添加了额外的预告片
Timber Twig template - sticky post doesn't just push to top of list, it adds extra teaser to the page
我有添加 12 post/page: 6 的代码(如下),部分模板使这 6 个更大;和 6 个获得模板使它们更小 - 这工作正常,直到其中一个帖子是粘性的,然后粘性正确地进入列表的顶部,但现在有 7 个较小的帖子。
PHP 文件:
<?php
/**
* Template Name: Blog Landing Page
* Template Post Type: page
*/
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$context = Timber::context();
$timber_post = new Timber\Post();
$context['post'] = $timber_post;
$newsArgs = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => array(
'date' => 'DESC'
));
$context['news'] = new Timber\PostQuery($newsArgs);
Timber::render( 'layouts/layout-blog.twig', $context );
还有树枝:
{% for post in news|slice(0,6) %}
{% include "partial/teaser-article.twig" %}
{% endfor %}
{% for post in news|slice(6,12) %}
{% include "partial/teaser-article-small.twig" %}
{% endfor %}
{% include 'partial/pagination.twig' with { pagination: news.pagination({show_all: false, mid_size: 1, end_size: 1}) } %}
非常感谢任何建议!
Twig 的切片有两个参数 - 开始和长度:
https://twig.symfony.com/doc/3.x/filters/slice.html
因此,您可能需要 slice(6,6)
而不是 slice(6,12)
我有添加 12 post/page: 6 的代码(如下),部分模板使这 6 个更大;和 6 个获得模板使它们更小 - 这工作正常,直到其中一个帖子是粘性的,然后粘性正确地进入列表的顶部,但现在有 7 个较小的帖子。
PHP 文件:
<?php
/**
* Template Name: Blog Landing Page
* Template Post Type: page
*/
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$context = Timber::context();
$timber_post = new Timber\Post();
$context['post'] = $timber_post;
$newsArgs = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => array(
'date' => 'DESC'
));
$context['news'] = new Timber\PostQuery($newsArgs);
Timber::render( 'layouts/layout-blog.twig', $context );
还有树枝:
{% for post in news|slice(0,6) %}
{% include "partial/teaser-article.twig" %}
{% endfor %}
{% for post in news|slice(6,12) %}
{% include "partial/teaser-article-small.twig" %}
{% endfor %}
{% include 'partial/pagination.twig' with { pagination: news.pagination({show_all: false, mid_size: 1, end_size: 1}) } %}
非常感谢任何建议!
Twig 的切片有两个参数 - 开始和长度:
https://twig.symfony.com/doc/3.x/filters/slice.html
因此,您可能需要 slice(6,6)
slice(6,12)