如何在wordpress的RSS端添加广告?
我已经在functions.php的主题中添加了一个函数如何在wordpress的RSS端添加广告?,wordpress,rss,ads,Wordpress,Rss,Ads,我已经在functions.php的主题中添加了一个函数 函数插入符($content){ $content=$content.“添加到此处”; 返回$content;} add_filter('the_content_feed','insertad') add_filter('the_extract_rss','insertad') 问题是,我让add显示在每个内容下,而不是rss页面的末尾。我怎样才能解决这个问题呢?WordPress没有为你想做的事情提供一个挂钩。你会把广告放在哪个元素中
函数插入符($content){
$content=$content.“添加到此处”;
返回$content;}
add_filter('the_content_feed','insertad')代码>
add_filter('the_extract_rss','insertad')代码>
问题是,我让add显示在每个内容下,而不是rss页面的末尾。我怎样才能解决这个问题呢?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');
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');
所以没有解决方法?我已经检查过feed-rss2.phpWell,您可以使用[output buffering][1]:if(is_feed()){ob_start('your_function');}
并附加数据。但RSS只是在项目之外不提供广告的位置。[1] :有没有办法知道最后一个内容以便在最后一个内容上显示添加内容?感谢您的回复:)我必须将代码修改为if($counter<(2*$max))
因为如果我按照您建议的方式离开,广告将开始显示在最大值的一半上。我想这是因为当我们使用内容提要
或摘录rss
时,完成了两个调用。非常感谢你,所以没有工作了?我已经检查过feed-rss2.phpWell,您可以使用[output buffering][1]:if(is_feed()){ob_start('your_function');}
并附加数据。但RSS只是在项目之外不提供广告的位置。[1] :有没有办法知道最后一个内容以便在最后一个内容上显示添加内容?感谢您的回复:)我必须将代码修改为if($counter<(2*$max))
因为如果我按照您建议的方式离开,广告将开始显示在最大值的一半上。我想这是因为当我们使用内容提要
或摘录rss
时,完成了两个调用。非常感谢你。