php RSS Feed Show在其他博客上

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php RSS Feed Show在其他博客上相关的知识,希望对你有一定的参考价值。



<?php
//add post thumbnails to RSS images
function cwc_rss_post_thumbnail($content) {
    global $post;
    if(has_post_thumbnail($post->ID)) {
        $content = '<p>' . get_the_post_thumbnail($post->ID) .
        '</p>' . get_the_excerpt();
    }
 
    return $content;
}
add_filter('the_excerpt_rss', 'cwc_rss_post_thumbnail');
add_filter('the_content_feed', 'cwc_rss_post_thumbnail');
?>
 
 
<?php 
$rss = fetch_feed('http://www.worldoweb.co.uk/feed');
 
 
if (!is_wp_error( $rss ) ) : 
 
    $maxitems = $rss->get_item_quantity(5); 
    $rss_items = $rss->get_items(0, $maxitems); 
endif;
?>
<?php function get_first_image_url($html)
        {
            if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
            return $matches[1];
            }
        }
?>  
 <?php
function shorten($string, $length)
{
    $suffix = '&hellip;';
    $short_desc = trim(str_replace(array("r","n", "t"), ' ', strip_tags($string)));
    $desc = trim(substr($short_desc, 0, $length));
    $lastchar = substr($desc, -1, 1);
        if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
                    $desc .= $suffix;
        return $desc;
}
?>
<ul class="rss-items" id="wow-feed">
    <?php 
        if ($maxitems == 0) echo '<li>No items.</li>';
        else 
        foreach ( $rss_items as $item ) : ?>
    <li class="item">
        <span class="rss-image">
            <?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
        </span>
        <span class="data">
            <h5><a href='<?php echo esc_url( $item->get_permalink() ); ?>' title='<?php echo esc_html( $item->get_title() ); ?>'> <?php echo esc_html( $item->get_title() ); ?></a></h5> 
            <span class="date-image">&nbsp;</span><small><?php echo $item->get_date('F Y'); ?> </small>
            <span class="comment-image">&nbsp;</span><small><?php $comments = $item->get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');?><?php $number = $comments[0]['data']; ?>
                <?php if ($number == '1'){ echo $number."&nbsp;". "Comment"; } else {echo $number. "&nbsp;"."Comments";}?></small>
            <p><?php echo shorten($item-> get_description(),'150');?></p>
        </span>
    </li>
    <?php endforeach; ?>
</ul>


以上是关于php RSS Feed Show在其他博客上的主要内容,如果未能解决你的问题,请参考以下文章

从RSS Feed中删除图像将Feed添加到其他站点时的说明

PHP 仅在作者页面上显示WordPress作者RSS Feed

PHP Twitter RSS Feed Parser在网站上显示推文(包括缓存)

PHP 实例 - AJAX RSS 阅读器

PHP Wordpress:在RSS Feed中显示帖子缩略图

如何链接在php mysql中创建的RSS feed