Feed modification
-
How can I create my own feeds? I would like to create a feed url such as: http://www.mysite.com/myposturl/?feed=myfeed
When accessed, myfeed will access a specific feed template that will pull content for myposturl.
thoughts?
ps – atom is my prefered feed type
-
Easy.
function do_feed_myfeed($for_comments) { // do whatever is needed to produce a feed here... // Basically, like what is done in feed-rss2.php or feed-atom.php } add_action('do_feed_myfeed', 'do_feed_myfeed', 10, 1);Make something like that into a plugin. If you make it load a separate template file like that, you should use the load_template() function to load that template file, like so:
load_template(ABSPATH.PLUGINDIR.'/your-plugin-name/myfeed.php');Thx, but I think Ill take the road less traveled.
PS – when do you think the codex will be updated with 2.5 feed information?
Otto,
This is how I have been using feeds prior to 2.5:in wp-feed.php
<?php if (empty($doing_rss)) { $doing_rss = 1; require(dirname(__FILE__) . '/wp-blog-header.php'); } // Remove the pad, if present. $feed = preg_replace('/^_+/', '', $feed); if ($feed == '' || $feed == 'feed') { $feed = 'rss2'; } if ( is_single() || ($withcomments == 1) ) { require(ABSPATH . 'wp-commentsrss2.php'); } else { switch ($feed) { case 'atom': require(ABSPATH . 'wp-atom.php'); break; case 'rdf': require(ABSPATH . 'wp-rdf.php'); break; case 'rss': require(ABSPATH . 'wp-rss.php'); break; case 'rss2': require(ABSPATH . 'wp-rss2.php'); break; case 'comments-rss2': require(ABSPATH . 'wp-commentsrss2.php'); break; case 'overview': require(ABSPATH . 'ssn-overview.php'); break; case 'audience': require(ABSPATH . 'ssn-audience.php'); break; case 'screens': require(ABSPATH . 'ssn-screens.php'); break; case 'creative': require(ABSPATH . 'ssn-creative.php'); break; case 'lp_overview'; require(ABSPATH . 'ssn-lp-overview.php'); break; case 'lp_ditl'; require(ABSPATH . 'ssn-lp-ditl.php'); break; case 'lp_activities'; require(ABSPATH . 'ssn-lp-activities.php'); break; case 'lp_research'; require(ABSPATH . 'ssn-lp-research.php'); break; case 'shortDesc'; require(ABSPATH . 'ssn-shortDesc.php'); break; case 'eh_overview'; require(ABSPATH . 'ssn-eh-overview.php'); break; case 'vc_overview'; require(ABSPATH . 'ssn-vc-overview.php'); break; case 'lph_overview'; require(ABSPATH . 'ssn-lph-overview.php'); break; case 'lp_relatedVenues'; require(ABSPATH . 'ssn-lp-relatedVenues.php'); break; } } ?>I am not versed in creating a plugin. I have looked at the codex and at some example plugins, but just ‘dont get it’ yet.
Here is what I am doing in 2.5 (functions.php):
function do_feed() { global $wp_query; $feed = get_query_var( 'feed' ); // Remove the pad, if present. $feed = preg_replace( '/^_+/', '', $feed ); if ( $feed == '' || $feed == 'feed' ) $feed = get_default_feed(); $hook = 'do_feed_' . $feed; if ( !has_action($hook) ) { $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), wp_specialchars($feed)); wp_die($message); } do_action( $hook, $wp_query->is_comment_feed ); } /* Begin SSN Feeds */ function do_feed_audience() { load_template( ABSPATH . WPINC . '/ssn-audience.php' ); } /* End SSN Feeds */What I understand is that the url parameter is passed as a variable to the function call. so do_feed_audience should be called if the requested url is http://www.url.com/postOrPage/?feed=audience.
What returns is “ERROR: audience is not a valid feed template”
when I do this:
$hook = 'do_feed_' . $feed; if ( !has_action($hook) ) { do_feed_audience(); }The feed is displayed correctly.
Thoughts??
This problem drove me crazy too… the issue is you need to put
add_action(‘do_feed_myfeed’, ‘do_feed_myfeed’, 10, 1);
under actions in default-filters.phpThankyou! I’ve been trying to figure this out for the last day or so.
Also, surprisingly easy to put into a plugin. Much more update-proof than editing the core files. Thanks!
Kristarella,
I would love to see your plugin to do this as I am plugin retarded!best,
shuaOtto,
I don’t need a full customized feed, I just need to separate the Tags from Categories. It seems that WordPress puts them all in <Category>. Is there an easy way to do that, or do I need a new feed template?
Thanks
Steve
The topic ‘Feed modification’ is closed to new replies.