FAQ in listing page

I want to show FAQ below the listing page for each listings. How to do this. Is there any plugin which provides this functionality.

Please check if there are any plugins for this purpose that support custom post types (“hp_listing” in this case). There’s no such feature in HivePress, but it may be possible in future versions via the Repeater field. If the FAQ is the same for all listings this may also be possible via the template customizations Customizing Templates I HivePress Developer Docs - YouTube

Thanks for the reply @ihor . I have seen the video about template customization but it is very short and not clear to understand. I got the below code to add a header hero in listing page. Is it possible to modify the same to add custom html to the below part of listings . Just above the footer.

add_filter(
	'hivetheme/v1/areas/site_hero',
	function( $output ) {
		if ( is_singular( 'hp_listing' ) ) {
			?>
			<section class="header-hero header-hero--large">
				<div class="header-hero__content">
					<div class="container">
						custom content here
					</div>
				</div>
			</section>
			<?php
		}

		return $output;
	}
);
1 Like

Please try this PHP snippet but please note that it can require further customization

add_filter(
	'hivepress/v1/templates/listings_view_page',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_content' => [
						'blocks' => [
							'custom_listings_block' => [
								'type' => 'content',
								'content' => '<p>Your content here</p>',
								'_order' => 30,
							],
						],
					],
				],
			]
		);
	},
	1000
);
1 Like

Thanks a lot @yevhen . My requirement was to show the same in listing page. Done that by altering your code.

Can you help me on the below queries.

  1. But how to show the content in between related listings and the footer?. Now it is showing on the top, above listing images.

  2. And my content is having more than 500 words. Is it a right way to add the same in functions.php? Or is it possible to save this in some where else and call.

  3. My contents is FAQ which will take listing title and other attributes from the listing for the questions and answers(Dynamically created FAQ for each listings). I’m able to get title part. How to do this for attributes. There is an attribute named phone number. How to retrieve it’s value and display it in FAQ content?

Sorry, this requires further customizations depending on how you store the questions/answers for a listing, where these should be located, and the required styling. If you’re familiar with customizations please check our short tutorial about customizing templates Customizing Templates I HivePress Developer Docs - YouTube

If you have a listing object, you can get the attribute value this way:

$listing->get_attributenamehere();

We’re also working on the full developer docs, planned for the next week.

1 Like
add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {
		include_once 'get_listing_faq.php';
		$text=TestBlockHTML (get_the_title());
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_content' => [	
						'blocks' => [
							'custom_listings_block' => [
								'type' => 'content',
								'content' => $text,
								'_order' => 121,
							],
						],
					],
				],
			]
		);
	},
);

My Idea is to show case same FAQ for all the listings where the answers will generate based on the attributes. Above code will display the FAQ with listing name as FAQ title (Eg: ‘Listing ABC - FAQ’). I want to pass other listing attributes to same function which will be used as answers. Can you help me on how to get the attribute. For example I have phone number as an attribute. How to get this done?

Thanks in Advance.

Sorry, this requires advanced customizations. Please try starting with this sample snippet, this way you can get the attribute values from the current listing:

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$attribute = $listing->get_your_attribute_name_here();
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'page_content' => [
								'blocks' => [
									'custom_attribute_block' => [
										'type' => 'content',
										'content' => $attribute,
										'_order' => 10,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000, 
	2
);

The rest of the implementation requires further code changes depending on your requirements. We’re working on the first version of the developer docs at the moment and plan to publish them within a week (we’ll send out a newsletter).

@yevhen Thanks a lot for your guidance. I have successfully done it. Added to custom blocks.

  1. Links of related pages (order=61)
  2. FAQ of listing (order=121)

Can you help me to change the display order. I’m really confused with the ‘order’ property. Even I have swapped the orders shown above. It is not working. And is it possible to move a block below the related listing section .

Please try this PHP snippet instead of the previous one to move your custom block below the related listings section

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$attribute = $listing->get_your_attribute_name_here();
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'page_footer' => [
								'blocks' => [
									'custom_attribute_block' => [
										'type' => 'content',
										'content' => $attribute,
										'_order' => 1000,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000, 
	2
);

Hi, I want to do a similar block like your FAQs block on the listing page. I tried this code you posted put it did not work.

Can you share how you placed a FAQs block on the listing page? Is there a way to do it with just a code snippet or do I have to create it through a child theme (which I have no idea how to create yet), so I am hoping a simple code snippet can work for me, and I can just custom the text on it. Thanks in advance

Hi, I’m not an expert here. I have done that in my own way to increase the SEO.
you have to do the below steps.

  1. Create a child theme.
  2. FAQ is same for all the listings but the answers will change based on listing attributes. You have to write PHP code to retrieve the attributes from listings to prepare the dynamic questions and answers.
  3. Design an FAQ accordion in HTML and CSS. (I have integrated FAQ schema also).
  4. Save PHP file which contains FAQ in child theme folder.
  5. Add custom code in functions.php file to load FAQ on all listings.

If you are confident in doing the above steps then I will guide you.

1 Like