Hi, what does your Block Template look like?
Ive limited the excerpt like this,
in your functions.php add
//limit length of Excerpt
function limit_words($string, $word_limit) {
// creates an array of words from $string (this will be our excerpt)
// explode divides the excerpt up by using a space character
$words = explode(' ', $string);
// this next bit chops the $words array and sticks it back together
// starting at the first word '0' and ending at the $word_limit
// the $word_limit which is passed in the function will be the number
// of words we want to use
// implode glues the chopped up array back together using a space character
return implode(' ', array_slice($words, 0, $word_limit));
}
Im using the “post” block type to display a chose post, in the template im using the following to display & limit the exerpt..
<?php echo limit_words(get_the_excerpt(block_sub_value( 'your-block-type-sub-value' )->ID), '55'); ?>
mines a sub-value as its in a repeater field, so adjust that as necessary..
hope that helps?
This is the whole php for this block.
<?php
// Variables
$post_count = block_value( 'number-of-posts' );
$post_type = block_value( 'post-type' );
// WP_Query arguments
$args = array(
'post_type' => array( $post_type ),
'posts_per_page' => $post_count,
'category__in' => array( 40 ),
);
// The Query
$post_grid_query = new WP_Query( $args );
// The Loop
while ( $post_grid_query->have_posts() ) {
$post_grid_query->the_post();
?>
<div class="block-the-norwegian-posts--post">
<div class="block-the-norwegian-posts--post-thumbnail" style="background-image: url('<?php the_post_thumbnail_url( 'large' ); ?>');">
</div>
<div class="block-the-norwegian-posts--post-content">
<a href="<?php the_permalink(); ?>">
<h4 align="center"><?php the_title(); ?>
</a>
</h4>
<p><?php the_excerpt(); ?></p>
<a class="read-more" href="<?php the_permalink(); ?>">Read More</a>
</div>
</div>
<?php
}
// Restore original Post Data
wp_reset_postdata();
?>
Never mind I’m an idiot sometimes, I hadn’t actually created an excerpt, all sorted.