comments_template(). Y se encarga de cargar el fichero comments.php de nuestro theme, si existe.
function comments_template( $file = '/comments.php' ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( ! (is_single() || is_page() || $withcomments) )
return;
$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);
/** @todo Use API instead of SELECTs. */
if ( $user_ID) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date", $post->ID, $user_ID));
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post->ID));
} else {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date", $post->ID, $comment_author, $comment_author_email));
}
// keep $comments for legacy's sake (remember $table*? ;) )
$comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
$wp_query->comment_count = count($wp_query->comments);
update_comment_cache($comments);
define('COMMENTS_TEMPLATE', true);
$include = apply_filters('comments_template', TEMPLATEPATH . $file );
if ( file_exists( $include ) )
require( $include );
else
require( ABSPATH . 'wp-content/themes/default/comments.php');
}Si nos fijamos en la definición de la función, esta compruba que el fichero comments.php exista en nuestro template, y en caso de existir lo incluye para mostrar su contenido, en caso de no existir, utilizará el del template default de Wordpress para no perder la funcionalidad.
Una vez cargado, nos encontramos una estructura similar a esta:
<?php if(!emptyempty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
<?php endif; ?>
<?php if(!emptyempty($post->post_password)) : ?>
<?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
<?php endif; ?>
<?php endif; ?>
<?php if($comments) : ?>
<?php foreach($comments as $comment) : ?>
<?php if ($comment->comment_approved == '0') : ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else : ?>
<?php endif; ?>
<?php if(comments_open()) : ?>
<?php if(get_option('comment_registration') && !$user_ID) : ?>
<?php else : ?>
<?php if($user_ID) : ?>
<?php else : ?>
<?php endif; ?>
<?php endif; ?>
<?php else : ?>
<?php endif; ?>No voy a entrar más en detalle, por que los chicos de AyudaWordpress lo han hecho ya y es imposible mejorar la traducción que han hecho sobre este gran artículo de NETTUTS.
Artículos relacionados
You have already tagged this post. Your tags: