Hello,
I couldn’t add to the existing topic “Add description to listing block” since it’s now closed but I was wondering if it’s possible to display just the 5 first lines and not the entire description. Also, is it possible to add the Tags below it?
Thank you
Philippe
yevhen
August 4, 2022, 11:22pm
3
Please try this PHP snippet but please note that it can require further customization
add_filter(
'hivepress/v1/templates/listing_view_block/blocks',
function( $blocks, $template ) {
$listing = $template->get_context('listing');
if(!$listing){
return $blocks;
}
$description = $listing->get_description();
if (strlen( $description ) > 120 ) {
$description_parts = explode( ' ', substr( $description, 0, 120 ) );
$description_parts[ count( $description_parts ) - 1 ] = '...';
$description = implode( ' ', $description_parts );
}
$tags = $listing->get_tags();
$tag_view = [];
foreach((array)$tags as $tag){
$tag_view[] = $tag->get_name();
}
return hivepress()->helper->merge_trees(
[ 'blocks' => $blocks ],
[
'blocks' => [
'listing_content' => [
'blocks' => [
'listing_description' => [
'type' => 'content',
'content' => '<p>'.$description.'</p>',
'_order' => 40,
],
'listing_tags' => [
'type' => 'content',
'content' => implode(', ', $tag_view),
'_order' => 40,
],
],
],
],
]
)['blocks'];
return $blocks;
},
1000,
2
);
3 Likes
It’s working perfectly, thanks a lot!
system
Closed
September 4, 2022, 12:16pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.