Guys,
I'm having trouble with a new plugin I'm developing (my first one!) that is supposed to how in every single.php page a list of posts from exactly one year before. Sorry for the parts in which I'm using the Portuguese language, but the plugin structure itself is very understandable, I reckon:
<?php
/*
Plugin Name: Um Ano Atrás...
Plugin URI: http://macmagazine.com.br/blog/
Description: Lista os posts de um ano atrás na página de leitura do artigo.
Author: Rafael Fischmann
Version: 1.0
Author URI: http://macmagazine.com.br/blog/
*/
function um_ano_atras() {
global $wpdb, $posts, $post;
$sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND day(post_date) = day('$post->post_date') AND month(post_date) = month('$post->post_date') AND year(post_date) = year('$post->post_date') - 1 ORDER BY post_date DESC";
$posts = $wpdb->get_results($sql);
$output = '<h2>Um Ano Atrás...</h2>';
$output .= '<ul>';
if($posts) {
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$permalink = get_permalink($post->ID);
$output .= '<li><a href="' . $permalink . '" rel="bookmark" title="' . htmlspecialchars($post_title, ENT_COMPAT) . '">' . htmlspecialchars($post_title) . '</a></li>';
}
} else {
$output .= "<li>Não houve nenhum post há um ano.</li>";
}
$output .= '</ul>';
echo $output;
}
?>
The plugin seems to be working fine (showing the list of posts from one year before in each post page), however it's messing up the post comments. Can anybody tell me what's wrong?!
Thanks in advance!