TIGblogs TIG | TIGblogs GROUP TIGBLOGS LOGIN SIGNUP
betzster's Blog
betzster's Blog
Tidy up the RSS

I’ve been playing around with backing up my tweets lately. At this point I’m using the Twitter Tools plugin to create a weekly digest. Since I created a Tumble-blog not to long ago to share social stuff like this I also wanted the tweets to go to tumblr. Part of this was just a way to clean up Tumblr and not create a new post everytime I tweet.

Now, having the tweets on the blog is mostly for me. I didn’t want to bombard people that are subscribed to the RSS feed with this weekly mashup of all my tweets, but still be able to have the RSS feed to send to Tumblr or for anybody that wants it.

This is what I ended up doing:

function tweetRSS123($query) {
	if ($query->is_feed && !is_category()) {
		$query->set('cat','-1');
		}
return $query;
}

add_filter('pre_get_posts','tweetRSS123');

I got the idea somewhere on the web that I can’t remember. The big change that I made was !is_category(). Which just says if it’s a category archive, don’t do anything. So it won’t remove the category from RSS if you actually take the RSS of that category.

So far it seems to be working. It’s hard to tell if it’s going to get along with the W3 Total Cache plugin, but I think I’m finally at a point where it’s going to work. It’s going to be really awesome if this works because I just spent an hour throwing together a plugin to send it to Tumblr just-in-case, but I’d really rather not use it.

If You Want to Use It

So there are two ways of using this snippet in your own theme. The way I’m doing it is to put this in the functions.php file for your theme, which gets treated just like a plugin except that it’s on a per-theme basis. This is where you can put any PHP function that are specific to your theme.

The other way would be to to add just a little bit more code and install it as a plugin, which is probably what I’ll be doing a little later when I get some free time to throw that together. The advantage of using something like this as a plugin instead of in your functions file is that it stays around for any theme that you use. If you forget to add this to the next theme you use though, your category is going to show up again.

You’ll have to remember to change the ‘-1′ value to the negative of the category ID that you want to exclude. The value is negative because we want to exclude it. If it were positive it would only include that category, which probably isn’t a good idea for your RSS feed.


February 27, 2010 | 11:02 AM Comments  0 comments

Tags:
You must be logged in to add tags.


Josh's Profile


Latest Posts
Ultrabooks aren’t...
Hypersonic
What Powers Instagram...
Laravel Tutorials →
Roots Hide WP

Monthly Archive
April 2007
May 2007
June 2007
July 2007
August 2007
September 2007
October 2007
November 2007
December 2007
March 2008
April 2008
May 2008
June 2008
July 2008
September 2008
October 2008
November 2008
December 2008
January 2009
February 2009
March 2009
April 2009
May 2009
June 2009
July 2009
August 2009
September 2009
October 2009
November 2009
December 2009
January 2010
February 2010
March 2010
April 2010
June 2010
July 2010
August 2010
September 2010
October 2010
November 2010
December 2010
January 2011
February 2011
March 2011
April 2011
June 2011
September 2011
October 2011
November 2011
December 2011
January 2012
March 2012
April 2012
May 2012

Change Language


Tags Archive
apache apple asides band blog blogs coding design dreamweaver florida gallery general globalwarming hosting internet johnmayer network nifty php plugins school service tech theme themes twitter vacation web wordpress youtube

Links
High School Reunion
Josh Betz Blog
Josh Betz Professional
Josh Betz Projects


29577 views
Important Disclaimer