在我的wordpress帐户中显示来自twitter的提要


Display feeds from twitter in my wordpress account

我的twitter账号url-> https://script.google.com/macros/s/AKfycbyp8Wwo8-dxWdPjO0atNZJbKPpy0LRaDTszisMWZhsdXU0XYOs/exec有rss订阅

我正在使用以下代码来显示提要,但无法这样做。Result is no item.

<?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://script.google.com/macros/s/AKfycbyp8Wwo8-dxWdPjO0atNZJbKPpy0LRaDTszisMWZhsdXU0XYOs/exec' );
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>

有一个twitter插件,将为您做的工作。要访问插件网站,请点击这里

或者你可以在wp plugin的repo中搜索twitter-widget-pro

它为您提供了一个适当处理twitter提要的小部件,包括解析@username, #hashtag和url为链接。它支持显示个人资料图像,甚至可以让你控制是否显示tweet的时间和日期,或者它发生的时间(大约5小时前等)。

如果你知道wordpress插件的用法,我推荐这个:https://wordpress.org/plugins/latest-tweets-widget/