WordPress RSS作为邮政类型的馈送,并带有图像/永久链接



我有一个朋友,他写信给几个不同的博客,想从一个不流行的故事中汲取故事,并带有RSS feed的主要博客,并从它也(由于RSS提要有图像,有时)。

显示RSS提要不应该太难了,它使它们成为一种自定义的帖子类型,对我来说似乎更困难。

如果有人有任何想法,请拍摄。

编辑: - 有人知道如何使外部RSS feed以自定义帖子类型出现在WordPress中吗?

一种简单的方法可能是使用WordPress'自己的fetch_feed函数:http://codex.wordpress.org/function_reference/fetch_feed

一个快速示例(假设您已经设置了自定义帖子类型):

function import_feed_items()
{
  $feed = fetch_feed('http://feeds.bbci.co.uk/news/uk/rss.xml');
  if( !is_wp_error($feed) )
  {
    if( $last_import = get_option('last_import') )
    {
      $last_import_time = $last_import;
    } else {
      $last_import_time = false;
    }
    $items = $feed->get_items();
    $latest_item_time = false;
    foreach ( $items as $item )
    {
      $item_date = $item->get_date('Y-m-d H:i:s');
      if( $last_import_time && ($last_import_time >= strtotime($item_date)) )
      {
        continue;
      }
      $post = array(
        'post_content'   => $item->get_content(),
        'post_date'      => $item_date,
        'post_title'     => $item->get_title(),
        'post_status'    => 'publish',
        'post_type'      => 'custom_post_type'
      );
      wp_insert_post($post);
      if( strtotime($item_date) > $latest_item_time )
      {
        $latest_item_time = strtotime($item_date);
      }
    }
    if( false !== $latest_item_time )
    {
      update_option('last_import', $latest_item_time);
    }
  }
  else
  {
    echo $feed->get_error_message();
  }
}
add_action('wp', 'import_feed_items');

如果内容中有一个图像标签,则可以使用PHP的DomDocument类来获取URL并将其上传到您的服务器,因此您可以将其设置为特色图像。

http://codex.wordpress.org/function_reference/wp_insert_attachment

http://codex.wordpress.org/function_reference/set_post_thumbnail

编辑

更正时间戳检查。此更新的示例使用" WP"钩子运行,因此您可以更快地看到结果。最好将其设置为CRON任务。请参阅http://codex.wordpress.org/function_reference/wp_schedule_event

发布插件的提要是将多个RSS项目导入WordPress博客的完美解决方案,您甚至可以将它们存储为帖子或自定义帖子类型。

http://www.wprssaggregator.com/extension/feed-to-post/

不幸的是,我不知道有一条路,但是您是否考虑修改插件?周围有大量的内容策划插件(FeedWordPress,Autoblog等)。您可能可以在某个地方找到wp_insert_post()行并将其修改以包括您的自定义帖子类型/分类法。

编辑我自己跳入插件(feedWordPress),所有insert_post的东西都在syndicatedpost.class.php中 - 第1538行上的主要wp_insert_post()

edit 如果您在阅读插件代码时喜欢咯咯笑声,您会发现许多 f Word 的实例 ... haha

<</p>

嘿,为什么不尝试此http://wordpress.org/extend/plugins/display-latest-ratest-ratest-rates-feeds/它将从任何帐户中提取RSS提要,并将其显示到您的博客。不幸的是,它不会仅显示RSS Feeds标题及其代码链接到原始博客的图像,但是您可以在需要的情况下轻松修改源代码。

最新更新