Cómo añadir anuncios a finales de RSS en WordPress?
Pregunta
He añadido una función para functions.php en mi tema.
function insertAds($content) {
$content = $content.' add goes here';
return $content;}
add_filter('the_content_feed', 'insertAds');
add_filter('the_excerpt_rss', 'insertAds');
El problema es que estoy teniendo el complemento que aparece debajo de cada contenido, y no al final de la página RSS. ¿Cómo puedo arreglar eso?
Solución
WordPress no ofrece un gancho para lo que quiere hacer. En el que el elemento se ubicaría el anuncio?
La costumbre RSS-2-Feed tiene datos y elementos (el contenido) meta. No hay ningún otro elemento.
Ver wp-includes/feed-rss2.php
para más detalles.
Actualizar
Ajustar el siguiente código a sus necesidades y poner el archivo en el directorio de plugins:
<?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');
¿Es este el efecto que tenía en mente? Como se puede ver, la adición de contenido es bastante fácil. :)