How to add description to listing block

On the listing pages (for example Jobs), each ad currently shows only the title, location, and date. I want it to also show a short part of the description under the title or location for every ad.

Hi,

Thanks for the request. Please clarify, do you want to add a description to this page for the Location and Title fields? Or do you want to add a description on this page for Location and Title?

Hi Andrii, thanks for the reply.

To clarify my request:

I already have the two pages you mentioned.

My issue is with the listing cards (Jobs and other listing types). On the archive/search/category/home pages each box shows title, location, and date only.

I need the card to also show a short part of the Description (an excerpt of the main listing content), e.g., the first 20–30 words under the title.

Hi,

Please clarify, do you mean adding a description to the listing block, under the title (as shown in this screenshot)?

Hi @andrii,

I think I understand what @Amjad is trying to do, so hopefully, I can makes things clearer!

On individual listing blocks, below the title, I believe @Amjad wants to display a truncated version of the listing’s description field attribute.

I.e He wants to give a ‘preview’ of the listing details on the listing block before you view the actual listing page itself.

I hope that makes sense!

Cheers,
Chris :victory_hand:

1 Like

Thank you, yes that what is exactly I need @andrii if you can help in this regard, please.


attached is a picture for reference

1 Like


I want to showcase a short job description with my ad, giving job seekers a sneak peek into the role before they open the full job listing.

Hi,

Thanks for the details. Please use this PHP snippet:

add_filter(
	'hivepress/v1/templates/listing_view_block/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if($listing && $listing->get_description()){
			$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'listing_details_primary' => [
								'blocks' => [
									'custom_listing_block_description' => [
										'type'    => 'content',
										'content' => '<p>'.esc_html($listing->get_description()).'</p>',
										'_order'  => 6,
									],
								],
							],
						],
				]
				)['blocks'];
		}
		
		return $blocks;
	},
	1000,

You can add a PHP snippet using this doc: How to add custom code snippets - HivePress Help Center

I hope it helps

2 Likes

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