كيفية إضافة إعلانات إلى نهاية RSS على WordPress؟

StackOverflow https://stackoverflow.com/questions/2551645

  •  23-09-2019
  •  | 
  •  

سؤال

لقد أضفت وظيفة إلى الوظائف.

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