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 に答える