Skip Navigation

[Résolu] How to generate Video Thumnail in Views Archive Page Loop

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 5 réponses, has 2 voix.

Last updated by katrina Il y a 8 années.

Assigned support staff: Luo Yang.

Auteur
Publications
#162715

Hello,

I am using a plugin called Video Thumbnails in my WordPress site, which generates a thumbnail of the YouTube video embedded in the posts. I would like to include this thumbnail in my loop so that it displays in with the rest of the code generated in my custom archive page IF there is no featured image set, or else show the featured image. So far i only have it showing the featured image... can anyone shed any light on how to add to this script to achieve my goal?

thanks so much in advance on any help.

Katrina

<div id="mycontainer">

<!-- wpv-loop-start -->

<wpv-loop>

<div class="box">
[wpv-post-featured-image]<h2>[wpv-post-title]</h2>[wpv-post-excerpt]
</div>

</wpv-loop>
<!-- wpv-loop-end -->

</div>

This is the link to the plugin i am using, but i need a little help deciphering the jargon 🙂

#162716
#162717

UPDATE: I magically found the field video_thumbnail as an available insert from the 'fields' options available to me when creating my views loop. I am not sure if it was something i did while messing around that enabled it to show up there, or if it was already there before but i missed it because it was below all the other available inserts. But anyway, it is somehow in there (great!). So i used it as follows, but it isn't working (and I also suspect i would need to add an 'if, then, else statement' of sorts to stop it showing both thumbnail and featured image if both exists. For now though, this does NOT Seem to be working yet:

<div id="mycontainer">

<!-- wpv-loop-start -->

<wpv-loop>

<div class="box">

[wpv-post-field name="video_thumbnail"]

[wpv-post-featured-image]

<h2>[wpv-post-title]</h2>[wpv-post-excerpt]
</div>

</wpv-loop>
<!-- wpv-loop-end -->

</div>

#162724

Sorry for so many updates, i can't see where to edit my original question, but here's another updated. I managed to get the video thumbnail to work using this:

<img src="[wpv-post-field name="_video_thumbnail"]"/>

there were two things wrong originally, 1) I didn't realize the code retreived the URL and not the actual image, which was easily resolved by the corrected html, but also the code snipped that populated from the fields options placed 'video_thumbnail' in the loop, rather than _video_thumbnail , which was something i discovered and corrected after a bit of searching through the plugin developers support pages. Is this a glitch on the Video Thumbnails plugin developers end, or in Views?

Regardless, i'm thrilled to get one step closer my goal. Now is there any way to edit this following View loop so that it shows only one or the other of the Video Thumbnail or featured image? or is that something that can only be done writing a custom PHP archive page?

<wpv-loop>

<div class="box">

<img src="[wpv-post-field name="_video_thumbnail"]"/>

[wpv-post-featured-image]

<a href="[wpv-post-url]"><h2>[wpv-post-title]</h2></a>

[wpv-post-excerpt]

</div>

</wpv-loop>

Thanks again in advance, and for your patience in reading this thread...

#163337

Luo Yang
Supporter

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi katrina,

Thanks for the details,
1) I guess the _video_thumbnail image URL is generated by the plugin "video-thumbnails", if the custom field slug is start with "_", it means Hidden Custom Fields:
If you are a plugin or theme developer and you are planning to use custom fields to store parameters related to your plugin or template, it is interesting to note that WordPress will not show custom fields which have keys starting with an "_" (underscore) in the custom fields list on the post edit screen or when using the the_meta() template function. This can be for example used to show these custom fields in an unusual way by using the add_meta_box() function.
http://codex.wordpress.org/Function_Reference/add_post_meta#Hidden_Custom_Fields

So I don't think it is a glitch on the Video Thumbnails plugin developers end, or in Views

2) I assume you are going to check if custom filed "_video_thumbnail" is empty, if empty, display "featured image", else display "_video_thumbnail"
Please try use Views shortcode for it, like this:

[wpv-if video_thumbnail="_video_thumbnail" evaluate="empty($video_thumbnail)"][wpv-post-featured-image][/wpv-if]
[wpv-if video_thumbnail="_video_thumbnail" evaluate="!empty($video_thumbnail)"]<img src="[wpv-post-field name="_video_thumbnail"]"/>[/wpv-if]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#checking-for-empty-fields

#163798

Hi Louy,

That works perfectly, and thanks for the link for more help with conditional output.

(and for the info about hidden custom fields!)

I do have another question...

I am using the method of simply pasting the YouTube URL in my post content to generate the video (instead of embedding it like i used to do) but this is causing the URL to display in my post excerpt (which is generated automatically from text in the man content). Is the only way to avoid this by using the actual Excerpt field in the edit post screen?

Katrina