# Add Category and Desc. Preview to Listing Cards

**URL:** <https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347>\
**Category:** HivePress\
**Created:** [April 15, 2023, 5:00am UTC](https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347 "2023-04-15T05:00:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![highwayman](https://community.hivepress.io/user_avatar/community.hivepress.io/highwayman/32/5035_2.png) [@highwayman](https://community.hivepress.io/u/highwayman)\
**Post date:** [April 15, 2023, 5:00am UTC](https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347/1 "2023-04-15T05:00:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [April 15, 2023, 11:27am UTC](https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347/2 "2023-04-15T11:27:32Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![highwayman](https://community.hivepress.io/user_avatar/community.hivepress.io/highwayman/32/5035_2.png) [@highwayman](https://community.hivepress.io/u/highwayman)\
**Post date:** [April 16, 2023, 9:33pm UTC](https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347/3 "2023-04-16T21:33:15Z")

</div>

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:

```auto
 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
 );

```

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [May 16, 2023, 9:33pm UTC](https://community.hivepress.io/t/add-category-and-desc-preview-to-listing-cards/5347/4 "2023-05-16T21:33:16Z")

</div>

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