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;
}
);
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
);
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.
-
But how to show the content in between related listings and the footer?. Now it is showing on the top, above listing images.
-
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.
-
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.
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.
- Links of related pages (order=61)
- 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
);