Support » Plugin: Related YouTube Videos » Make link of thumbnail instead of playing onclick

Viewing 1 replies (of 1 total)
  • Plugin Author Chris

    (@zenation)

    If you want to stick with using the shortcode or the widget this is not possible. Currently, there’s no templating system implemented and I’m not sure if it will be in the future.

    But you can always use PHP to this, e.g. directly in your theme files.

    /* Load the "Related YouTube Videos" API class if it does not exist yet. */
    if( !class_exists( 'RelatedYouTubeVideos_API' ) ) {
    
      $file = str_replace( '/', DIRECTORY_SEPARATOR, ABSPATH ) . 'lib' . DIRECTORY_SEPARATOR . 'RelatedYouTubeVidoes' . DIRECTORY_SEPARATOR . 'API.php';
    
      if( file_exists( $file ) ) {
    
        include_once $file;
    
      }
    
    }
    /* Only continue if the API class could be loaded properly. */
    if( class_exists( 'RelatedYouTubeVideos_API' ) ) {
    
      $RytvAPI  = new RelatedYouTubeVideos_API();
    
      /* Do your configuration */
      $data = $RytvAPI->validateConfiguration(
        array(
          'relation'  => 'postTitle',
          'max'       => '3',
          'width'     => 150,
          'height'    => 150
        )
      );
    
      /* Search YouTube. */
      $results  = $RytvAPI->searchYouTube( $data );
    
      /* Create your very own custom HTML */
      if( !empty( $results ) ) {
    
        foreach( $results as $video ) {
    
          // Try detecting the YouTube Video ID
          $videoID = ( preg_match( '#\?v=([^&]*)&#i', $video->link['href'], $match ) && isset( $match[1] ) ) ? (string) $match[1] : '';
    
          echo '<a href="' . $video->link['href'] . '"><img src="http://img.youtube.com/vi/' . $videoID . '/0.jpg" alt="" width="150" height="150" /></a>' . "\n";
    
        }
    
      }
    
    }

    Instead of templating system I think I might craft a more modular API that will make such a customazation more easy.

Viewing 1 replies (of 1 total)
  • The topic ‘Make link of thumbnail instead of playing onclick’ is closed to new replies.