on March 6, 2010 by Ignacio in Wordpress, Comments (0)

Función para generar un botón de ‘Recomendar a un amigo’

Con tal de que nuestros artículos sean publicitados si gustan a la gente, siempre puede ser interesante disponer de un botón que permita enviarlos por mail a alguien a quien el lector crea que les pueden interesar.

Para ello, abriremos functions.php, y pondremos el siguiente código al final de todo:

<?php
function direct_email($text="Enviar un mail a un amigo"){
global $post;
$title = htmlspecialchars($post->post_title);
$subject = 'En '.htmlspecialchars(get_bloginfo('name')).' : '.$title;
$body = 'Te recomiendo : '.$title.'. en esta página : '.get_permalink($post->ID);
$link = '<a rel="nofollow" href="mailto:?subject='.rawurlencode($subject).'&amp;body='.rawurlencode($body).'" title="'.$text.' : '.$title.'">'.$text.'</a>';
return $link;
}
?>

Sólo nos faltará poner allí donde creamos conveniente en nuestro template (dentro del loop) el siguiente nuevo template tag que hemos creado:

Compartir <?php echo direct_email('par mail') ?> con un amigo

Esperamos que lo pongáis en práctica y vuestros comentarios al respecto.

No Comments

Leave a comment

XHTML: Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spanish flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagEnglish flagGerman flagFrench flagJapanese flagArabic flagRussian flag