I’ve adapted texnixe’s earlier suggestion at https://forum.getkirby.com/t/variable-length-excerpts-possible/1073/4 to the following:
<?php
function getExcerpt($string){
$start = strpos($string, '<p>');
$string = substr($string, $start, 350);
$string = strip_tags($string, '<strong>');
return $string . "…";
}
?>
I added this as a new index.php
file in my new plugin folder, in a folder called Methods
.
This works exactly as I wanted in my original post. The getExcerpt
method ignores any KirbyTags at the beginning of the KirbyText file, starting at the first <p>
, counting up the to the number of characters set in the attributes. I added strp_tags
to remove any unwanted paragraph breaks.
Thanks Sonja for your help!