如何将广告添加到RSS的WordPress的结束?
题
我已经添加到的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页的结束。我该如何解决呢?
解决方案
WordPress的不提供你想要做什么挂钩。在该元素将放置广告?
在通常的RSS -2-饲料具有元数据和项目(内容)。有没有其他的元素。
详细见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');
这是你心目中的影响?正如你所看到的,增加的内容是相当容易的。 :)
不隶属于 StackOverflow