0

我刚刚安装了 SimplePie 来解析我的 RSS 提要以显示在我的网站上。我已经尝试过他们的教程来获取自定义 XML 标记,但没有成功。

自定义标签为:<odat:image>http://www.image.com/images/items/image.jpg</odat:image>

我想将标签分解为不同的变量,以便我可以随意格式化信息的显示。有任何想法吗?

谢谢!

当前的 SimplePie 代码:

foreach ($feed->get_items() as $item):?>

    <div class="item">
        <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
        <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
    </div>

<?php endforeach;?>
4

1 回答 1

-1

尝试

$items = $feed->get_items();
foreach ($items as $item):?>

    <div class="item">
        <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
        <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
    </div>

<?php endforeach;?>

这应该可以解决您的问题

要获取提要中的自定义元素,您可以使用get_item_tags()一组标签,这些标签将返回
http://simplepie.org/wiki/reference/simplepie_item/get_item_tags

如果您使用 print_r() 检查数组,您应该能够找到所需的数据以及如何访问它

直流

于 2011-01-28T01:51:05.773 回答