質問

私は自分のテーマにの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');

これはあなたが考えていた影響か?あなたが見ることができるように、コンテンツを追加することは比較的容易です。 :)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top