Add Category and Desc. Preview to Listing Cards

Hey there,

I’m running the TaskHive theme. How could I set the category of each listing to display on its card much like how attributes can be displayed?

Also would it be possible for me to get it to display a short preview of the description?

Kind regards,
Tony

Hi,

It’s possible, but this would require code customizations (to embed the description text into the listing_view_block template). There may be an existing sample snippet, please try searching topics by “listing_view block description”.

Hi Ihor,

I managed to write a PHP snippet to show a description preview (truncated at 100 chars) for each listing card. I’m leaving it here as reference for anyone else who may want to add this functionality:

 add_filter(
   'hivepress/v1/templates/listing_view_block/blocks',
   function ($blocks, $template) {
       $listing = $template->get_context('listing');

    if ($listing && $listing->get_description()) {
             $description = $listing->get_description();
 
             // Truncate the description at 100 characters
             if (strlen($description) > 100) {
              $description = substr($description, 0, 100) . '...';
             }

           $blocks = hivepress()->helper->merge_trees(
                ['blocks' => $blocks],
                 [
                     'blocks' => [
                         'listing_content' => [
                             'blocks' => [
                                 'custom_listing_description' => [
                                   'type'    => 'content',
                                     'content' => '<p>' . $description . '</p>',
                                 '_order' => 1000,
                                 ],
                             ],
                        ],
                     ],
              ]
            )['blocks'];
         }
 
        return $blocks;
     },
     1000,
    2
 );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.