在WordPress中无法解析中等RSS提要

时间:2017-05-08 作者:Krishnan G

这是我的代码我的代码

我需要在我的wordpress站点中添加“medium”rss提要,但它显示了错误,我在此处添加了图像enter image description here

<?php /* Template Name: CustomPageT1 */?>

<?php get_header(); ?>
<rss version="2.0">


<h2><?php _e( \'Recent news from Some-Other Blog:\', \'my-text-domain\' ); ?></h2>

    <?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://medium.com/feed/krishnan\' );

    var_dump($rss);

    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>
<!-- .content-area -->


<?php get_sidebar(); ?>
<?php get_footer(); ?>

1 个回复
SO网友:Krishnan G

这是我的rss链接代码,但它不起作用,请帮助我找到解决方案

include_once( ABSPATH . WPINC . \'/feed.php\' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( \'https://medium.com/feed/......\' );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
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;
?>

结束