Dynamically replacing sushi while parsing an rss feed
Posted: Sat Mar 29, 2008 10:59 pm
Hi everyone,
This is my first post here at devnetwork and I come to ask for help with a script modification I can NOT seem to get to work.
I am not very knowledgable in PHP and am in the process of learning, but after 3 days of searching and reading up online, I still can't seem to get this to do what I want it to. I know it's possible and the solution is probably so simple I'll be kicking myself when it finally works.
Anyway, hello to you all and I hope someone here will be kind enough to help me out with this.
First of all, here is the script in it's original working form. This script uses the built in rss parser in wordpress and the code below outputs a list of 10 headlines from just about any rss feed. In the example below, I've included a Google News Search feed for the word "sushi".
See the rss feed url on line 4 with the word sushi in it.
Now, here's what I want to do to modify the script a bit.
I want to replace the word "sushi" with a php tag that will insert the title of my blog post in there.
So I'll use this tag:
...and the google news feed url will now look like...
but it simply doesn't work and I've tried everything I know (and that's not much).
Can someone please make some suggestions as to how to dynamically insert the output of the wp_title tag into the middle of that url?
Thank you in advance for any help or suggestions you may offer.
If I figure it out for myself I'll post my modified code here.
Paul
This is my first post here at devnetwork and I come to ask for help with a script modification I can NOT seem to get to work.
I am not very knowledgable in PHP and am in the process of learning, but after 3 days of searching and reading up online, I still can't seem to get this to do what I want it to. I know it's possible and the solution is probably so simple I'll be kicking myself when it finally works.
Anyway, hello to you all and I hope someone here will be kind enough to help me out with this.
First of all, here is the script in it's original working form. This script uses the built in rss parser in wordpress and the code below outputs a list of 10 headlines from just about any rss feed. In the example below, I've included a Google News Search feed for the word "sushi".
See the rss feed url on line 4 with the word sushi in it.
Code: Select all
<?php
require_once (ABSPATH . WPINC . '/rss-functions.php');
// insert the feed URL here
$rss = @fetch_rss('http://news.google.com/news?hl=en&ned=&q=sushi&ie=UTF-8&output=rss');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<?php
// set the number of items from the feed to display (10)
$rss->items = array_slice($rss->items, 0, 10);
foreach ($rss->items as $item ) {
?>
<li>
<a href='<?php echo wp_filter_kses($item['link']); ?>'>
<?php echo wp_specialchars($item['title']); ?></a>
</li>
<?php } ?>
<?php } ?>I want to replace the word "sushi" with a php tag that will insert the title of my blog post in there.
So I'll use this tag:
Code: Select all
<?php wp_title(); ?>Code: Select all
$rss = @fetch_rss('http://news.google.com/news?hl=en&ned=&q=<?php wp_title(); ?>&ie=UTF-8&output=rss');Can someone please make some suggestions as to how to dynamically insert the output of the wp_title tag into the middle of that url?
Thank you in advance for any help or suggestions you may offer.
If I figure it out for myself I'll post my modified code here.
Paul