Hi I’m trying to add a video file submitted under the attribute “Video Tour” into my listing page. I previously used this PHP code to do that for the values assigned to a checkboxes attribute:
Now I want to do it for a video file but I’m unsure exactly how the code should be altered. Here’s what I have with the help of ChatGPT. What am I doing wrong?
add_filter(
'hivepress/v1/templates/listing_view_page/blocks',
function( $blocks, $template ) {
$listing = $template->get_context('listing');
if (!$listing) {
return $blocks;
}
$video_tour_id = $listing->get_attribute('video_tour');
if (!$video_tour_id) {
return $blocks;
}
$video_tour_url = wp_get_attachment_url($video_tour_id);
if (!$video_tour_url) {
return $blocks;
}
return hivepress()->template->merge_blocks(
$blocks,
[
'page_content' => [
'blocks' => [
'custom_video' => [
'type' => 'content',
'content' => '<video controls><source src="' . esc_url($video_tour_url) . '" type="video/mp4">Your browser does not support the video tag.</video>',
'_order' => 76,
],
],
],
]
)['blocks'];
},
1000,
2
);
Sorry, we can’t compose a custom code snippet for adding new functionality according to our support scope, but I can provide some guidance or suggest a workaround. I highly recommend using the existing features instead of custom coding:
You can allow adding videos to the listing gallery in HivePress/Settings/Listings, then users can upload videos along with images to the listing gallery slider.
You can add a custom Attachment or Ember attribute in Listings/Attributes and assign it to the Ternary (Page) display area, then the uploaded or embedded video will appear full-width under the listing image slider.
However, I’m running into a recurring problem with displaying the video. Although the URL value is being correctly called, the video player appears empty and doesn’t play any video. I think I’m not understanding how to properly display videos. I also tried your suggestion of uploading it on the page in the Ternary display area but encountered the same issue. Here’s the code I used under the format box:
<video width="320" height="240" controls>
<source src="%video%" type="video/mp4">
Your browser does not support the video tag.
</video>
Whenever I pressed save, the <source src="%video%" type="video/mp4"> line got deleted, and the same issue occurred.
Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress
Hi, I’m not asking for any customization. In Ihor’s response to me, he gave me a second option of creating an attachment attribute and listing it in the ternary display. However, the format currently has it shown as a URL when in his response, he said the “video will appear full-width under the listing image slider”. What do I input in the format box in order to make it show the video, and not just a URL linking to the video.
I see. Sorry for the confusion. If you mean display area, then please try to use a ternary area and specify the display format you posted above, but with the %value% token (the value will change to the attachment URL if the Video attribute was added as an attachment).