1

我在我的主题上向 functions.php 添加了一个函数。

function insertAds($content) {

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

return $content;}

add_filter('the_content_feed', 'insertAds');

add_filter('the_excerpt_rss', 'insertAds');

问题是我在每个内容下都显示了添加,而不是在 rss 页面的末尾。我该如何解决?

4

1 回答 1

1

WordPress 没有为您想要做的事情提供挂钩。您会将广告放置在哪个元素中?

通常的 RSS-2-Feed 有元数据和项目(内容)。没有其他元素。详情请参阅wp-includes/feed-rss2.php

更新

根据您的需要调整以下代码并将文件放入您的插件目录:

<?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/">validating</a></p>
MY_ADDITIONAL_CONTENT;
    }
}
add_filter('the_content_feed', 'ad_feed_content');
add_filter('the_excerpt_rss',  'ad_feed_content');

这是你心目中的效果吗?如您所见,添加内容相当容易。:)

于 2010-03-31T09:42:39.443 回答