views:

31

answers:

1

I have added a function to functions.php on my theme.

function insertAds($content) {

$content = $content.' add goes here';

return $content;}

add_filter('the_content_feed', 'insertAds');

add_filter('the_excerpt_rss', 'insertAds');

The problem is that I'm having the add displayed under each content, and not at the end of the rss page. How can I fix that?

+1  A: 

WordPress doesn’t offer a hook for what you want to do. In which element would you place the ad?

The usual RSS-2-Feed has meta data and items (the content). There is no other element. See wp-includes/feed-rss2.php for details.

Update

Adjust the following code to your needs and put the file into your plugin directory:

<?php
/*
Plugin Name: Last man adding
Description: Adds content to the last entry of your feed.
Version: 0.1
Author: Thomas Scholz
Author URI: http://toscho.de
Created: 31.03.2010
*/

if ( ! function_exists('ad_feed_content') )
{
    function ad_feed_content($content)
    {
        static $counter = 1;
        // We only need to check this once.
        static $max = FALSE;

        if ( ! $max )
        {
            $max = get_option('posts_per_rss');
        }

        if ( $counter < $max )
        {
            $counter++;
            return $content;
        }
        return $content . <<<MY_ADDITIONAL_CONTENT
<hr />
<p>Place your ad here. Make sure, your feed is still
<a href="http://beta.feedvalidator.org/"&gt;validating&lt;/a&gt;&lt;/p&gt;
MY_ADDITIONAL_CONTENT;
    }
}
add_filter('the_content_feed', 'ad_feed_content');
add_filter('the_excerpt_rss',  'ad_feed_content');

Is this the effect you had in mind? As you can see, adding content is rather easy. :)

toscho
so there is no work around for that? I have already checked feed-rss2.php
zeina
Well, you could use [output buffering][1]: `if ( is_feed() ) { ob_start('your_function'); }` and append your data. But RSS just offers *no place* for ads outside of the items.[1]: http://www.php.net/manual/en/function.ob-start.php
toscho
I really did not get it.
zeina
Is there a way to know the last content so to display the adds just on the last one?
zeina
Thanks for your reply :)Well I had to modify the code to this`if ( $counter < (2*$max ) ) ` cause if I left it they way you suggested, the ads will start to display on half of the max. I guess this is because whe we use `the_content_feed` or `the_excerpt_rss` two calls are done. Thank you very much.
zeina