go41

UPDATE: YouTube user channel rss feed import without API key :: Reply by Joern

von Joern am 9. Mai. 2015 | Keine Kommentare

Same YouTube user channel feed import as above, but totally modified code using the WordPress function fetch_feed( $uri );

on Google+ Thomas Scholz (toscho) https://plus.google.com/115532307838378431827 asked me to sanitize the output and cache the result. Thank you!

fetch_feed caches for 12 hours by default, you might want to change this with wp_feed_cache_transient_lifetime (check yourself..)

fetch_feed also uses the WP sanitization class KSES (KSES Strips Evil Scripts) to validate the input (too high for me :? )

Here the code for fetching latest clips of a youtube channel, just title and image with link to the video on YT

Code:

<aside class="widget">
<h3 class="widget-title">Our Youtube Channel</h3>
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'https://www.youtube.com/feeds/videos.xml?channel_id=your CHANNEL ID' ); // use just the link of your feed ..
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
    // Figure out how many total items there are, but limit it to 3.
    $maxitems = $rss->get_item_quantity( 3 );
    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<ul>
    <?php if ( $maxitems == 0 ) : ?>
        <li><?php _e( 'No items', 'my-text-domain' ); ?></li>
    <?php else : ?>
        <?php // Loop through each feed item and display each item as a hyperlink. ?>
        <?php foreach ( $rss_items as $item ) : ?>
            <li>
                <a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank" title="<?php echo esc_html( $item->get_title() ); ?>"> <?php echo esc_html( $item->get_title() ); ?></a>
      <?php if ($enclosure = $item->get_enclosure()) // we get the thumbnail image link
            { $thumbnail = $enclosure->get_thumbnail();
               $thumbnail = substr($thumbnail, 0,-13); // cut off 'hqdefault.jpg' and add new filename below
               $thumb1 = $thumbnail."1.jpg"; // is a 120 wide image, Medium Quality Thumbnail (320x180 pixels) would be mqdefault.jpg
                  echo '<p><a href="' . esc_url( $item->get_permalink() ) . '" target="_blank" title="' . esc_html( $item->get_title() ) . '"> <img src="' . esc_url($thumb1) . '" width="120" height="90" alt="' . esc_html( $item->get_title() ) . '"/></a></p>';
            } ?>
                  <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>      
            </li>
        <?php endforeach; ?>
    <?php endif; ?>
</ul>
</aside>

Try it somewhere in sidebar or footer, ask if you get a problem
____________________
you find me on Google+, Twitter and Facebook

(von: Joern)

Hier noch 1 weitere Ergebnisse dieses Threads:

YouTube user channel rss feed import without API key

9. Mai. 2015 (von: Joern)

How to import the latest videos of a Youtube Channel to your sidebar.With youtube api v3 there are also some changes to the rss feed, so the long time used way to import the feed with player is not working…

Autor:

Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

weitere forum Beiträge: