Hi there, i have a custom attribute called program_summary that I would like to show as the main content of the listing block. However I would like to truncate the text to 200 character or less in the listing block. I have used the code below that works well to make it happen:
add_filter(
'hivepress/v1/templates/listing_view_block/blocks',
function ($blocks, $template) {
$listing = $template->get_context('listing');
if ($listing) {
// Check if program summary is not empty
$program_summary = $listing->get_program_summary();
if ($program_summary) {
// Limit the program_summary to 200 characters if necessary
if (strlen($program_summary) > 200) {
$program_summary = substr($program_summary, 0, 200) . '...';
}
$blocks = hivepress()->helper->merge_trees(
['blocks' => $blocks],
[
'blocks' => [
'listing_content' => [
'blocks' => [
'custom_listing_description' => [
'type' => 'content',
'content' => '<p>' . esc_html($program_summary) . '</p>',
'_order' => 1000,
],
],
],
],
]
)['blocks'];
}
}
return $blocks;
},
1000,
2
);
This code seems to work well, however the text is added after the ternary attribute section while I would like it in the primary attribute section or before ternary attribute section.
See picture of html, how do I achieve that?
Thank you!