Posts Tagged youtube

YouTube/Photos Thumbnails on WordPress Similar Posts Plugin List

If you are working with “Similar Posts” plugin, and videos / images on your posts, maybe you would like to display a post thumbnail for each post on your related posts list.
Se você está trabalhando com o plugin WordPress “Similar Posts”, e vídeos / imagens em seus posts, talvez você gostasse de exibir um thumbnail de cada post em sua lista de posts relacionados.

There are three very simple steps.
São três passos muito simples.

1) First of all, take a look on this post, where I talk about my YouTube Thumbnails workaround on WordPress.
Primeiramente, dê uma olhada no post em que falo sobre minha solução para thumbnails do YouTube no WordPress.

2) Go to wp-admin/settings and on “Similar Posts” Output/Output template, you will paste the code from the next step.
Vá até wp-admin/configurações e em “Similar Posts” Output/Output template, você colará o código do próximo passo.

3) Then you can use my workaround, and the code bellow, together, to display a list of similar posts, with images of your posts(photo, YouTube thumbnails) and a default image for those posts without media.
Então você pode usar minha solução, e o código abaixo, juntos, para exibir uma lista de posts similares com imagens do seu post(thumbnails de fotos, do YouTube) e uma imagem padrão para aqueles posts sem mídia.

<div>
<span><a href={url} title={title}>
<img src={imagesrc} alt={title} {php:if(strval({imagesrc})==""):echo "style='display:none;'";endif;}>
{php:$videolnk ="";$videolnk = get_post_meta({postid}, 'link_video', true);$videolnk = str_replace('http://www.youtube.com/watch?v=','http://img.youtube.com/vi/',$videolnk); if($videolnk!=''):$videolnk = $videolnk.'/2.jpg';endif;if(strval({imagesrc})==""&& $videolnk!=""):echo "<img alt='videolnk' src=$videolnk width=150>";endif;if(strval({imagesrc})==""&& $videolnk==""):echo "<img src='yourdefaultthumbnailimage'>";endif;}
</a></span>
{link}
</div>

It uses PHP + “Similar Posts” custom tags to control and display the thumbnails.
Ele usa PHP + mais tags customizadas do “Similar Posts”, para controlar e exibir os thumbnails.

I hope you find this useful. Good luck!
Espero que você ache útil. Boa Sorte!

Advertisements

, ,

Leave a comment

Display YouTube Thumbnail with wordpress custom field

Note:

Before using the code bellow, I strongly recommend you to take a look on my YouTubeNails plugin, wich is a evolution of the function bellow and you can easily configure as a widget.

Why saving a video thumbnail for a video hosted on YouTube, when you can use the YouTube API plus WordPress Custom Fields to display the thumb, without working around crops, size and other stuff like this.

All you need:

  1. Create a custom field called(slug) “link_video”, which contains the standard “share” url from YouTube, something like this http://www.youtube.com/watch?v=kBN9_deleBg&#8221;;
  2. Use the code bellow, to retrieve data, inside a WordPress Loop;
<?
if (have_posts()) : 				
  global $post;
  $strquery = "category_name=videos";
  $myposts = get_posts($strquery);
  if($myposts):
	foreach($myposts as $post) :
             setup_postdata($post);
            // get meta from the custom field, using its slug
            $videolnk = get_post_meta($post->ID, 'link_video', true);
            // pure php string replace
           // add the standard YouTube API call for video thumbnails
           $videolnk = str_replace('http://www.youtube.com/watch?v=','http://img.youtube.com/vi/',$videolnk);
           $videolnk .= "/2.jpg";
        endforeach;
  endif;
endif;
?>

Then you can call the code bellow on your page(inside the loop):

<a href="<?=get_permalink()?>">
<img src="<?=$videolnk?>" width="214" height="129" >
</a>

Go to the source, if you need further info about YouTube API.

, ,

9 Comments

%d bloggers like this: