質問

Working with Wordpress on this. I'm using Magpie to grab an RSS feed, but I only want it to display items that include a specific image. Here is the particular tag that I want to search for:

<media:thumbnail url="http://media.publicbroadcasting.net/wfpl/events/images/ourPick5.gif"/>

And here's the specific code I'm using in this application. It's basic, and I'm not incredibly adept at Magpie or PHP (I'm assuming there are more elegant ways of doing this for someone with a more robust knowledge of PHP):

<?php include_once(ABSPATH.WPINC.'/rss.php'); $feed = fetch_rss('http://www.publicbroadcasting.net/wfpl/.eventsfeed'); $items = array_slice($feed->items, 0, 4);?>

<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>

<?php if (!preg_match('/<media:thumbnail\surl\="http:\/\/media.publicbroadcasting.net\/wfpl\/events\/images\/ourPick5.gif".+?>/i', $item['description'])) 
continue; ?>

    <li><a href="<?php echo $item['link']; ?>"><div class="item-headline"><?php echo $item['title']; ?></div>
    <div class="item-info"><?php echo $item['description']; ?>
    </div></a></li></ul>

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

Again, I only want to display the items with that specific image url in the "media:thumbnail" tag and discard all other items.

役に立ちましたか?

解決

Add this part,

<?php if (!preg_match('/<media:thumbnail\surl\="http:\/\/media.publicbroadcasting.net\/wfpl\/events\/images\/ourPick5.gif".+?>/i', $item['description'])) 
    continue; ?>

before

<li><a href="<?php echo $item['link']; ?>"><div class="item-headline"><?php echo $item['title']; ?></div>
    <div class="item-info"><?php echo $item['description']; ?>
    </div></a></li>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top