Multiple Custom Thumbnails
-
Hi Frank,
Long time. Hope you’re well : )
We were discussing thumbnails in this thread.
Now that you have lyte_match_thumburl in the plugin, perhaps you can help me get my head around how to use it to implement multiple thumbnails associated with multiple videos on a page.
The only way I can think of this working is having the thumb url as an argument in the shortcode to associate it with the correct video, which would probably mean a bit of hacking the plugin.
But perhaps there’s a different and / or better way that you know of?
Many thanks
-
Afternoon Simon;
Well, I would store the custom thumbnail(s) in custom field(s) of the blogpost (custom fields can be set in the post editor) as a key-value pair, e.g. lyte_iECeetxtm0g (which contains the ID of the vid) as key and http://upload.wikimedia.org/wikipedia/commons/5/5e/The_Bad_Plus_(Ethan_Iverson,_Reid_Anderson,_David_King).jpg as value (the alternate image).Then I would add hook a function to the lyte_match_thumburl filter and check the custom field for the URL to use for that video (or video’s, if you have more then one in a post) based on the key (lyte_iECeetxtm0g).
That should just work 🙂
hope this helps,
frankThat sounds like the one! Thanks, Frank.. will try it out.
Hello again, Frank.
For videos added to posts with httpv, how do I grab the ID of a video just before lyte_parse() executes?
This would be in order to get the value of the corresponding Custom Field key and apply it to the filter.
Many thanks
you could use the “lyte_content_preparse” filter and use a regex to extract httpv-urls?
but when using “lyte_match_thumburl” you’ll have the URL to the original thumbnail as input, which contains the ID, so you could extract it from there, no?
frank
Perhaps I’m not understanding the filter / function.
If I use this in functions.php:
add_filter('lyte_match_thumburl','lyte_my_own_thumburl'); function lyte_my_own_thumburl($thumb) { return "http://www.kevinlikes.com/wp-content/uploads/2014/09/jonah-745.jpg"; }It replaces the thumbnails of all videos on a page. But where does the ID go to make it selective?
I could do it something like this:
add_filter('lyte_match_thumburl','lyte_my_own_thumburl'); function lyte_my_own_thumburl($thumb) { $video_id = '_zzrf8KK2FU'; $video_image = get_post_meta(get_the_id(), $video_id, true); return $video_image; }I know that’s not complete (needs to step through all custom fields to obtain keys), but it’s to explain my other two issues:
1. WordPress doesn’t like _zzrf8KK2FU as a custom field key. Won’t store it.
2. We are already using custom fields for other things on the website, so obtaining only the video ID keys gets tricky.So now my thinking is towards using Advanced Custom Fields plugin to create a more “dedicated area” for video IDs and thumb URLs.
But perhaps I’m going on a tangent when the answer is simpler?
“when using “lyte_match_thumburl” you’ll have the URL to the original thumbnail as input, which contains the ID”
add_filter('lyte_match_thumburl','lyte_my_own_thumburl'); function lyte_my_own_thumburl($thumb) { return "http://www.kevinlikes.com/wp-content/uploads/2014/09/jonah-745.jpg"; }I’m still not understanding where the filter accepts the video ID to link it to the correct video. Sorry if I’m missing something really obvious, Frank.
Regarding the custom field key; use “lyte_zzrf8KK2FU”?
regarding having multiple custom fields; as you have the key (see code below) that doesn’t matter (else you could always get all custom fields in an array (or not setting the third value, “single”, to true in get_post_meta) and loop over it).
Something like this should work (you’ll have to replace the magic with actual magic though);
add_filter('lyte_match_thumburl','lyte_my_own_thumburl',10,1); function lyte_my_own_thumburl($thumb) { $video_id="lyte_".magic_to_extract_id_from_thumb($thumb); $video_image = get_post_meta(get_the_id(), $video_id, single); return $video_image; }Thanks Frank, ok let’s take this for a test drive..
Can I formulate my question another way? How would I modify the code below:
add_filter('lyte_match_thumburl','lyte_my_own_thumburl'); function lyte_my_own_thumburl($thumb) { return "http://www.kevinlikes.com/wp-content/uploads/2014/09/jonah-745.jpg"; } add_filter('lyte_match_thumburl','lyte_my_other_thumburl'); function lyte_my_other_thumburl($thumb) { return "https://i.ytimg.com/vi/ArqoaJq3fXU/sddefault.jpg"; }..to separately target videos added to a post with:
httpv://www.youtube.com/watch?v=_zzrf8KK2FU httpv://www.youtube.com/watch?v=ArqoaJq3fXU..so the first video has the first thumbnail, and the second video has the second thumbnail.
I still can’t get my head around how the filter / function actually hooks into specific video IDs. How it catches different httpv links at the point at which they execute.
well, the point is that $thumb (coming in as parameter of your lyte_my_own_thumburl-function) will automatically hold the default YT thumbnail URL, so you can use that to extract the video ID 🙂
frank
Thanks Frank. Still stumped about how/why that works, but if/when I figure it out I’ll post more detail here.
well, a plugin with a filter typically does;
$plugin_variable="this is a string"; $plugin_variable=apply_filter("filter_name",$plugin_variable);when adding a filter to that hook, you’ll get the variable from the plugin as input and can do stuff with that:
add_filter('filter_name','my_filtered_var',10,1); function my_filtered_var($in) { return $in." with some text added"; }Autoptimize does this for the “lyte_match_thumburl”-hook, providing the filter with the default thumbnail URL that contains the video ID, so if you use the string stored in $thumb you should be able to extract the ID 🙂
frank
ok, and the filter fires every time httpv fires..
hmm.. ok, I’m learning, and appreciate it : )ok, and the filter fires every time httpv fires..
yep 🙂
The topic ‘Multiple Custom Thumbnails’ is closed to new replies.