首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在wordpress上的RSS末尾添加广告?

如何在wordpress上的RSS末尾添加广告?
EN

Stack Overflow用户
提问于 2010-03-31 17:10:34
回答 1查看 603关注 0票数 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页面的末尾。我怎么才能修复它呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-31 17:42:39

WordPress不会为你想要做的事情提供钩子。您会将广告放在哪个元素中?

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

更新

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

代码语言:javascript
复制
<?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');

这就是你想要的效果吗?如您所见,添加内容相当简单。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2551645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档