Come aggiungi annunci al fine di feed RSS su wordpress?
Domanda
Ho aggiunto una funzione per functions.php sul mio tema.
function insertAds($content) {
$content = $content.' add goes here';
return $content;}
add_filter('the_content_feed', 'insertAds');
add_filter('the_excerpt_rss', 'insertAds');
Il problema è che sto avendo aggiungi visualizzati di sotto di ogni contenuto, e non alla fine della pagina rss.Come posso risolvere?
Soluzione
WordPress non offre un gancio per quello che vuoi fare.Elemento si sarebbe svolto l'annuncio?
Il solito RSS-2-Feed è meta di dati e di elementi (il contenuto).Non c'è nessun altro elemento.Vedere wp-includes/feed-rss2.php
per ulteriori dettagli.
Aggiornamento
Regolare il seguente codice per le vostre esigenze e di mettere il file nella directory dei plugin:
<?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');
È questo l'effetto che si ha in mente?Come si può vedere, l'aggiunta di contenuto è piuttosto facile.:)