Site logo

Archived topic

Dynamic content - video player in archive page

9 replies · Started by Dan on January 24, 2022

Viewing posts 1–10 of 10

Hi,
I have a CPT - 'Videos'. On the single pages of the CPT I have the video player along with the transcription of the video and some meta data information.
On the Archive page of that CPT I would like to have instead of a feature image for every single post the actual video of the single post, so the user can play the video on the archive page without going to the single post.
How can I get the embedded (either Youtube/Vimeo or HTML5) video code to appear in the CPT archive page using the dynamic content element?

Thanks!
Dan

Hi there,

not sure if thats possible at this time - well not via the GP Dynamic Content Block.
How is the video URL added to the CPT? Is it in a Custom Field ?

Hi David, thanks for responding.
The video URL is either an embedded Vimeo video or a link to the video file with a Video block.
I would work it out to be a custom field using an ACF block, would that help?

Dan

I’m not sure how to do this but it a cool idea! Following!

Hi Dan and Brad,

I think this is doable w/ Block Element - Content Template.

But the issue here is you'll have to create a shortcode that'll serve as a helper function to output the video HTML w/ its values fetched from the content of this video CPT.

I'm not sure how you've placed the video URL but a suggestion would be to have a field for the video URL so the shortcode can fetch the dynamic video URL tied to the specific CPT by fetching the value through get_post_meta('get_the_ID','video_url_field',true);

You're basically going to have to do something like:

<?php
add_shortcode('video_cpt_embed',function(){
$vidurl = get_post_meta('get_the_ID','video_url_field',true);
?>
<iframe src="<?php echo $vidurl; ?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
<?php
});

You then use [video_cpt_embed] on the Block Element - Content Template so an iframe w/ a dynamic source shows up instead of an image.

Thank you Elvin.
I will give this a try.

Dan

Tip: If you get any problems w/ fetching field values, try doing a var_dump of the variable first. :D

No problem. Let us know how it goes. :)

Just wanted to share how I figured this out:
1. Created a content template element for single posts in the 'Video' CPT.
2. In that element, I created a few custom fields (single fields), one of them is the 'video-embed' field which accepts the embed code of the video. Since I'm using an iframe from Sprout Video (not a YouTube URL), this works well.
3. I have some other custom fields in this template such as the short description, links to documentation and github (dynamic buttons) and also the actual content.
4. in the Archive content element template I used the same 'video-embed' custom field which will display the actual video player in the archive page itself. We wanted to give the option for users to play the video without going to the standalone video page.

A cool (small) new thing I learned is that you can actually change the default names that GP gives the dynamic fields which makes it easier to manage the template if you have a few dynamic fields.

I'm attaching a screenshot of the single content template element for reference.
https://www.dropbox.com/s/dn1l33gel12rnps/gp-cpt-content-element.jpg?dl=0

Hope this helps other who are looking for a similar solution.

Dan

Hey that’s great!! Thanks for sharing. I’ll have to try it out on one of my development installs.

you're welcome, happy to share

This archived topic is closed to new replies.