Wordpress中的simplepie rss feed和reader

时间:2015-09-11 18:20:00

标签: php wordpress rss simplepie

尝试创建一个包含特色图片,标题和简要说明的简单阅读器。我现在拥有所有这些,但它包含的不仅仅是我想要的,而且我也不知道如何缩短它。

Feed实际上会显示两次精选图片。我试图将图像与描述分开,并找到了一个执行此操作的简短代码。但是我不知道要在我的读者中展示它的代码,所以现在它被从描述中删除了。每个末尾都有一个我想删除的模糊"帖子名字首先出现在..."。

我将帖子从http://blog.empow.me/feed提取到http://staging.empow.me(在页面底部列出)

这是我目前的代码:

<?php
// Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://blog.empow.me/topics/News/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 5. 
    $maxitems = $rss->get_item_quantity( 4 ); 

    // 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 _e( 'No items', 'my-text-domain' ); ?>
    <?php else : ?>
        <?php // Loop through each feed item and display each item as a hyperlink. ?>
        <?php foreach ( $rss_items as $item ) : ?>

        <div class="empowblog-block">

                <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>
        <p><?php echo $item->get_description(); ?></p>


            </div>

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

我并不熟悉编码,但我正在努力学习如何按照我们需要的方式工作。

谢谢!

0 个答案:

没有答案