【问题标题】:Wordpress - How to get a custom field from another wordpress blog via RSSWordpress - 如何通过 RSS 从另一个 wordpress 博客获取自定义字段
【发布时间】:2014-08-08 01:28:29
【问题描述】:

我需要通过 RSS 将其他 Wordpress 博客中的一些内容导入我的博客。目标博客包含一些我需要导入的自定义字段(例如:number_of_users)。我目前正在使用 fetch_feed 函数导入 RSS 提要,我不知道如何获取这些自定义字段的值。

这是我使用的代码:

<?php if(function_exists('fetch_feed')) {

    // include the required file
    $feed = fetch_feed('http://domaintoimportfeedfrom.com/feed/'); // specify the source feed

    $limit = $feed->get_item_quantity(7); // specify number of items
    $items = $feed->get_items(0, $limit); // create an array of items

}

if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
else foreach ($items as $item) : ?>

<div>
    <a href="<?php echo $item->get_permalink(); ?>" 
      title="<?php echo $item->get_date('j F Y @ g:i a'); ?>">
        <?php echo $item->get_title(); ?>
    </a>

    // need to get the "number_of_users" custom field

</div>

<?php endforeach; ?>

请指教。

也欢迎任何其他解决方案。

【问题讨论】:

    标签: php wordpress rss custom-fields


    【解决方案1】:
    <?php
    
    function getFeed($feed_url) {
    
      $content = file_get_contents($feed_url);
      $x = new SimpleXmlElement($content);
    
      echo "<ul>";
    
      foreach($x->channel->item as $entry) {
        echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
      }
      echo "</ul>";
    }
    ?>
    <?php getFeed("http://domaintoimportfeedfrom.com/feed/"); ?>
    

    http://code.tutsplus.com/articles/how-to-read-an-rss-feed-with-php-screencast--net-1272

    【讨论】:

    • 太好了,这正是我需要的解决方案。非常感谢您的快速回复!
    猜你喜欢
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    相关资源
    最近更新 更多