Algunas soluciones para WordPress sin necesidad de Plugins

WordPress es una de las aplicaciones para blogging más robustas y con una gran comunidad por detrás, siempre dispuesta a crear plugins que nos faciliten el trabajo. Sin embargo, muchas veces, dependiendo de los beneficios de nuestro hosting, algunos plugins pueden resultar molestos y sobrecargar los servidores de nuestros blogs.

A continuación una corta guía con algunas soluciones que te ahorraran algunos plugins:

Como mostrar los temas más populares:

Abre el archivo sidebar.php de tu theme y en el lugar que prefieras pega el siguiente código. Puedes cambiar «post populares» por el nombre que desees y el número 3 por el número de posts que desees que aparezcan en la lista.

<h2>Posts Populares</h2>
<ul>
<?php $result = $wpdb-?>get_results(«SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 3»);
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href=»http://www.blogger.com/%3C?php%20echo%20get_permalink($postid);%20?%3E» title=»»>»>
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

Como mostrar post relacionados

Abre el archivo functions.php y pega el siguiente código:

function related_posts_shortcode( $atts ) {
extract(shortcode_atts(array(
‘limit’ => ‘5’,
), $atts));

global $wpdb, $post, $table_prefix;

if ($post->ID) {
$retval = ‘<ul>’;
// Get tags
$tags = wp_get_post_tags($post->ID);
$tagsarray = array();
foreach ($tags as $tag) {
$tagsarray[] = $tag->term_id;
}
$tagslist = implode(‘,’, $tagsarray);

// Do the query
$q = «SELECT p.*, count(tr.object_id) as count
FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy =’post_tag’ AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID
AND p.post_status = ‘publish’
AND p.post_date_gmt < NOW()
GROUP BY tr.object_id
ORDER BY count DESC, p.post_date_gmt DESC
LIMIT $limit;»;

$related = $wpdb->get_results($q);
if ( $related ) {
foreach($related as $r) {
$retval .= ‘
<li><a title=»‘.wptexturize($r->post_title).'» href=»‘.get_permalink($r->ID).'»>’.wptexturize($r->post_title).'</a></li>
‘;
}
} else {
$retval .= ‘
<li>No related posts found</li>
‘;
}
$retval .= ‘</ul>
‘;
return $retval;
}
return;
}
add_shortcode(‘related_posts’, ‘related_posts_shortcode’);

Ahora cada vez que quieras insertar temas relacionados en algún post en particular, añade el siguiente código al final de tu post:

[related_posts]

Mostrar comentarios recientes:

Pues abrir el archivo sidebar.php o footer.php para mostrar los últimos comentarios de tu blog:

<?php
global $wpdb;
$sql = «SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ‘1’ AND comment_type = » AND post_password = » ORDER BY comment_date_gmt DESC LIMIT 10″;

$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= «n<ul>»;
foreach ($comments as $comment) {
$output .= «n<li>».strip_tags($comment->comment_author) .»:» . «<a href=»» . get_permalink($comment->ID).»#comment-» . $comment->comment_ID . «» title=»on «.$comment->post_title . «»>» . strip_tags($comment->com_excerpt).»</a></li>»;
}
$output .= «n</ul>»;
$output .= $post_HTML;
echo $output;
?>

DEJA UNA RESPUESTA

Por favor ingrese su comentario!
Por favor ingrese su nombre aquí