I’m looking for a method to put the three latest “news” from Google Blogsearch/Twitter search feeds into the bottom of category Pages. Maybe like this (assuming we’re on the archive page for the “Sports” category):
What others say about “Sport”:
- Instapundit – Michael Jordan Comeback!
- Huffington post – Michael Jordan Comeback!
- Crazyguy – Michael Jordan Comeback!
So we all know that you can put
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('pathtofeed.com', 3); ?>
in a template-file
and it will list the latest three items of a feed.
I would like to put the path to the feed of a query to Google Blogsearch, e.g. [http://blogsearch.google.com/blogsearch_feeds?hl=en&q=sport&ie=utf-8&num=10&output=rss][1]
Works fine. But I would like to replace the sport query
with the template tag for the category title – so it dynamically queries Google for a RSS-feed of sport searches
. I’ve tried this:
<?php
include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('www.blogsearch.google.com/blogsearch_feeds?hl=en&q=<?php single_cat_title() ?>&ie=utf-8&num=10&output=rss', 3);
?>
(omitted ‘http’ cause I can’t post hyperlinks here as a new user).
But all I get is:
There was a problem with the feed, try again later.
(translated from Danish error message).
Is it the syntax?
You’ve got a couple of issues in that code.
The first is you have a
<?php
inside an already opened<?php
section. Concatenation is the answer to that problem.The second is the function
single_cat_title()
displays the category title by default. Meaning it “echo()”s it out. So you need to tell that function to return the value not display it.My solution would be to add a line of code above your include there to get the category you’re looking for along the lines of:
The “false” tells the function to return it as a value instead of displaying it by default, the first parameter is the prefix or the text to display before the category title.
Then concatenate the current_category variable into your include statement
You can check out that function on the Template Tags page in the WordPress Codex.