如何在WordPress博客上显示任何RSS源

有时您希望在博客上显示外部RSS源。也许是您的另一个博客或其他网站的博客供稿。好吧,你不需要一个插件来做这个,因为WordPress有一个内置的功能,将负责这一点。在本文中,我们将向您展示如何在博客上显示外部RSS源。这样你甚至可以使用WordPress作为新闻聚合器。

只需将以下代码粘贴到您选择的任何WordPress文件中即可。最好是在您创建的自定义页面中。

  <h5><?php _e( "Recent news from Some-Other Blog:", "my-text-domain" ); ?></h5>    <?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.wpbeginner.com/feed/" );    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( 5 );        // 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() ); ?>"                      title="<?php printf( __( "Posted %s", "my-text-domain" ), $item->get_date("j F Y | g:i a") ); ?>">                      <?php echo esc_html( $item->get_title() ); ?>                  </a>              </li>          <?php endforeach; ?>      <?php endif; ?>  </ul>  

确保更改Feed网址和数量以及您喜欢的任何其他设置。

有时您希望在博客上显示外部RSS源。也许是您的另一个博客或其他网站的博客供稿。好吧,你不需要一个插件来做这个,因为WordPress有一个内置的功能,将负责这一点。在本文中,我们将向您展示如何在博客上显示外部RSS源。这样你甚至可以使用WordPress作为新闻聚合器。

只需将以下代码粘贴到您选择的任何WordPress文件中即可。最好是在您创建的自定义页面中。

  <h5><?php _e( "Recent news from Some-Other Blog:", "my-text-domain" ); ?></h5>    <?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.wpbeginner.com/feed/" );    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( 5 );        // 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() ); ?>"                      title="<?php printf( __( "Posted %s", "my-text-domain" ), $item->get_date("j F Y | g:i a") ); ?>">                      <?php echo esc_html( $item->get_title() ); ?>                  </a>              </li>          <?php endforeach; ?>      <?php endif; ?>  </ul>  

确保更改Feed网址和数量以及您喜欢的任何其他设置。

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。
超哥软件库 » 如何在WordPress博客上显示任何RSS源