Custom excerpts / post previews
-
I’m trying to create a custom post preview / excerpt when displaying a paginated list of posts (i.e., the standard Loop). I’m doing something like this
$context['posts'] = new PostQuery(); Timber::render('home-page.twig', $context);
and in home-page.twig
{% for post in posts %} ... other html like post title ... <p>{{ post.preview.length(25) }}</p> {% endfor %} {% include 'pagination.twig' with { pagination: posts.pagination({show_all: true}) } %}
I want to be able to use my own class method to create a custom excerpt based on the post content (I want to grab the first paragraph and use that).
How would I do that? It’s not clear if this is doable using the PostPreview class (https://timber.github.io/docs/reference/timber-postpreview/). I’ve tried modifying the PostQuery object but I’m not sure how to modify a PHP iterable object. I’ve tried
{{ function('the_excerpt') }}
but I run into problems trying to use a WordPress filter to modify the excerpt.
Suggestions? Thanks!
- The topic ‘Custom excerpts / post previews’ is closed to new replies.