Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1338155

    I’m adding videos to my YouTube channel daily. I have two separate Playlists: Daily Word and Courses. On two separate web pages I’m manually embedding the newest video URL from the “Daily Word” playlist. As you can imagine, I would like to automate this work process.

    I would like to always show the latest video from a playlist. So, only show one video on the pages, but always the most recent of the Daily Word playlist. When we upload a new Daily Word video on YouTube, that latest video has to be shown on these two web pages (see below).

    Example code:

    function requestLastVideo(playlistId, callback, pageToken) {
      var requestOptions = {
        playlistId: playlistId,
        part: 'snippet',
        maxResults: 50
      };
      if (pageToken) {
        requestOptions.pageToken = pageToken;
      }
      var request = gapi.client.youtube.playlistItems.list(requestOptions);
      request.execute(function(response) {
        var nextPageToken = response.result.nextPageToken;
        if (nextPageToken) {
          // we didn't reach the last page yet, fetch next one
          requestLastVideo(playlistId, callback, nextPageToken);
          return;
        }

    And you’d call this like so:

    var playlistItems = response.result.items;
        if (playlistItems) {
          var lastPlaylistItem = playlistItems[playlistItems.length - 1];
          callback(lastPlaylistItem.snippet);
        } else {
          alert('There are no videos');
        }
      });
    }

    You can play around with requestOptions.part to reduce the footprint of your call. With this parameter you can control which fields are present in the response. You can find more information detailling possible values in the YouTube API docs for this call.

    Two questions:

    1. Based on what I’m trying to achieve, will this work? Do you have any recommended changes?

    2. Naïve question, what HTML would I use on our page to render the video link?

    I hope I explained this properly. Let me know if you need any additional information. Thanks in advance for any guidance you can offer!!!

    #1338194

    Hey Julio,

    Thank you for the inquiry.

    You would have to pass the result to the Youtube Player API to dynamically load the video player using the data from the very last video.

    // https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player

    This is the structure of the resource.

    // https://developers.google.com/youtube/v3/docs/playlistItems#resource

    Unfortunately, this kind of modification is beyond the scope of support. You may need to hire a freelance developer or contact our partner, Codeable.

    // https://kriesi.at/contact/customization

    Best regards,
    Ismael

    #1338224

    btw. there are a lot of specialized Plugins (even free ones ) for that purpose. I use for a friend that one: youtube embed plus.
    You can show by shortcodes different channels with different options etc.
    See: https://kurzundschluss.com/

    #1338242

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1338263

    @ismael & @guenni007 I cannot thank you enough for sharing your insights and assistance for my request.

    I will definitely look into both approaches.

    Fact or Fiction? I have other WordPress users tell me not to use too many plugins because they can conflict with one another and your site, etc. Now, I don’t have enough experience/knowledge on this to share my opinion. When should you use Plug-Ins vs coding (PHP, JavaScript, etc.)? Thoughts?

    Thank you again for your help. I’m learning so very much…thanks to this forum and the Enfold Template.

    Best Regards,
    Julio

    #1338348

    Hi Julio,

    There’s not really any difference between code added to your site in a plugin, and code added in for example functions.php in your theme, they should work the same from both places. The problem with plugins can sometimes be that they are bloated, and can conflict with each other, or are not maintained on a regular basis. The good thing about plugins is that they can be easily deactivated, so that you can quickly debug if you should run into problems.

    Best regards,
    Rikard

    #1338380

    Thank you @Rikard. I fully appreciate your help!!

    For now, I’m following up on @guenni007’s suggestion to determine if the YouTube plug-in he suggested can meet my needs. If not, I’ll pursue the coding option that @ismael recommended.

    Feel free to close this for now.

    Thanks again to everyone who offered their assistance.

    Best Regards,
    Julio

    • This reply was modified 2 years, 9 months ago by Jules.
    #1338394

    Hi,

    Thanks for the update. I’ll go ahead and close this thread for now then, please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Get Latest Video in YouTube Playlist’ is closed to new replies.