Soporte > Temas
Problema como cuenta los comentarios mi diseño
(1/1)
23r9i0:
Hola mirar use el how to para separar los comentarios de lo pingbacks/trackbacks de sivel.net y añadi la opcion de descontar los ping en las entradas pero resulta que en el panel de administracion salen el numero total en todos los comentarios
Vease aqui:
El codigo que hace esto es el siguiente:
--- Código: ---<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
global $id;
$comments_by_type = &separate_comments(get_comments('post_id=' . $id));
return count($comments_by_type['comment']);
}
?>
--- Fin del código ---
Os pido ayuda para poder solucionarlo y poder actualizar mis diseños para que quien los descargue les funcione 100% 100%
y claro a mi tambien.
Tambien os pregunto si podeis probar en vuestro sitio para quitarme la duda de que el problema es solo mio ya que no encuentro ninguna solucion al respecto.
Saludos y gracias!
Angeles Portillo:
No sé responder a tu pregunta, por si te sirve, el theme que usamos en TodoWordPress lleva esto en comments.php:
--- Código: ---<?php if ($comments) : ?>
<?php
$comNo = get_comment_type_count('comment'); // Checking if there are any actual comments (trackbacks and pingbacks excluded)
$trackNo = get_comment_type_count('ping'); // Checking if there are any trackbacks and pingbacks
if ($comNo != 0) {
?>
<h3 id="comments"><?php comments_number('No hay comentarios', 'Un comentario', ''.$comNo.' comentarios' );?></h3>
<ul class="commentList">
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
<div class="commentLeft">
<?php echo get_avatar(get_comment_author_email(), '40'); ?>
</div>
<div class="commentRight">
<span class="commentAuthor"><?php comment_author_link() ?></span><br />
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('d/m/Y') ?></a> <?php edit_comment_link('editar',' ',''); ?></small>
<?php if ($comment->comment_approved == '0') : ?>
<small><em>Your comment is awaiting moderation.</em></small><br />
<?php endif; ?>
<?php comment_text() ?>
</div>
</li>
<?php
/* Changes every other comment to a different class */
$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
?>
<?php } ?>
<?php endforeach; /* end for each comment */ ?>
</ul>
<?php } ?>
<?php if ($trackNo != 0) { ?>
<h3 id="trackbacks">Trackbacks</h3>
<ol class="trackbackList">
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>
<?php } ?>
--- Fin del código ---
y esto en functions.php:
--- Código: ---/*
Ping/Track/Comment Count
Source URI: http://txfx.net/code/wordpress/ping-track-comment-count/
Description: Provides functions that return or display the number of trackbacks, pingbacks, comments or combined pings recieved by a given post. Other Authors: Mark Jaquith, Chris J. Davis, Scott "Skippy" Merrill
*/
function get_comment_type_count($type='all', $post_id = 0) {
global $cjd_comment_count_cache, $id, $post;
if ( !$post_id )
$post_id = $post->ID;
if ( !$post_id )
return;
if ( !isset($cjd_comment_count_cache[$post_id]) ) {
$p = get_post($post_id);
$p = array($p);
update_comment_type_cache($p);
}
if ( $type == 'pingback' || $type == 'trackback' || $type == 'comment' )
return $cjd_comment_count_cache[$post_id][$type];
elseif ( $type == 'ping' )
return $cjd_comment_count_cache[$post_id]['pingback'] + $cjd_comment_count_cache[$post_id]['trackback'];
else
return array_sum((array) $cjd_comment_count_cache[$post_id]);
}
function comment_type_count($type = 'all', $post_id = 0) {
echo get_comment_type_count($type, $post_id);
}
function update_comment_type_cache(&$queried_posts) {
global $cjd_comment_count_cache, $wpdb;
if ( !$queried_posts )
return $queried_posts;
foreach ( (array) $queried_posts as $post )
if ( !isset($cjd_comment_count_cache[$post->ID]) )
$post_id_list[] = $post->ID;
if ( $post_id_list ) {
$post_id_list = implode(',', $post_id_list);
foreach ( array('', 'pingback', 'trackback') as $type ) {
$counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
FROM $wpdb->posts
LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1' AND comment_type='$type' )
WHERE post_status = 'publish' AND ID IN ($post_id_list)
GROUP BY ID");
if ( $counts ) {
if ( '' == $type )
$type = 'comment';
foreach ( $counts as $count )
$cjd_comment_count_cache[$count->ID][$type] = $count->ccount;
}
}
}
return $queried_posts;
}
add_filter('the_posts', 'update_comment_type_cache');
?>
--- Fin del código ---
En el blog se visualizan correctamente los comentarios y los pings por separado.
En el blog si un post tiene 4 comentarios y 1 Trackback, aparece como suma: 4 comentarios, sin embargo en el panel de admin de wp aparece como 5 comentarios.
23r9i0:
Merci angeles!
Mañana lo miro mas tranquilamente ahora mismo mis ojos esta cerrandose, jeje
Saludos!
23r9i0:
Gracias Angeles!!!
Llevo como una semana buscando la manera de solucionarlo y con ayuda de tema que usais lo he podido arreglar, ahora solo tengo que arreglar unos detalles del idioma pero ahora mismo me ire a tomar un cafe con baileys a tu salud!!
Nos vemos
Angeles Portillo:
¡Bien! Me alegro que te haya servido ¡salud! :D
Navegación
Ir a la versión completa