Ad
Timber Twig Template - Sticky Post Doesn't Just Push To Top Of List, It Adds Extra Teaser To The Page
I have code (below) which adds 12 post/page: 6 with a partial template that makes those 6 bigger; and 6 that get a template making those smaller - this works fine, until one of the posts is a sticky, then the sticky correctly goes to the top of the list, but there are now 7 of the smaller posts.
PHP file:
<?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 );
And Twig:
{% 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}) } %}
Any suggestions greatly appreciated!
Ad
Answer
Twig's slice takes two parameters - start and length:
https://twig.symfony.com/doc/3.x/filters/slice.html
Therefore, instead of slice(6,12)
you probably want slice(6,6)
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad