php 获取最新的播客节目

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 获取最新的播客节目相关的知识,希望对你有一定的参考价值。

<div id="podcast" class="podcast">

  <h2>Podcast</h2>

  <div class="intro">
    <?php the_field('podcast_intro', 'option'); ?>
  </div>
  <!-- intro -->

  <h3>Latest episode</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://motiveunknown.libsyn.com/rss' );

$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 5.
  $maxitems = $rss->get_item_quantity( 1 );

  // Build an array of all the items, starting with element 0 (first element).
  $rss_items = $rss->get_items( 0, $maxitems );

endif;
?>


  <?php if ( $maxitems == 0 ) : ?>

  <?php else : ?>
      <?php // Loop through each feed item and display each item as a hyperlink. ?>
      <?php foreach ( $rss_items as $item ) : ?>

            <p>
                  <?php echo esc_html( $item->get_title() ); ?>
                  <?php // echo $item->get_description(); ?>
                  <!-- <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
                      title="<?php printf( __( 'Posted %s', 'motiveunknown' ), $item->get_date('j F Y | g:i a') ); ?>">View episode</a> -->
            </p>
              <?php
              // get MP3 link
                    if ($enclosure = $item->get_enclosure()){$enclosure->get_link();}
                    $mp3_url =  $enclosure->get_link();
              ?>

              <div class="player"><audio controls src="<?php echo $mp3_url; ?>"></div>

              <ul>
                <li>
                  <a href="https://motiveunknown.libsyn.com/rss"><svg><use xlink:href="#icon--rss" /></svg> Subscribe</a>
                </li>
                <li>
                  <a download href="<?php echo $mp3_url ?>"><svg><use xlink:href="#icon--download" /></svg> Download episode</a>
                </li>
              </ul>

      <?php endforeach; ?>
  <?php endif; ?>


</div>

以上是关于php 获取最新的播客节目的主要内容,如果未能解决你的问题,请参考以下文章