Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/01/2009, 17:58
Avatar de 23r9i0
23r9i0
 
Fecha de Ingreso: noviembre-2008
Ubicación: Catalonia
Mensajes: 203
Antigüedad: 16 años
Puntos: 33
Respuesta: Problema con poedit y linea de codigo!

Hola de nuevo!
Pero el % llamara a $comNo te pongo los códigos para que veas como trabaja.
Este es el código que hace que cuente solamente los comentarios no los pingbacks ni trackbacks.
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');

...
y este es donde se muestra el resultado

Código:
<?php
$comNo = get_comment_type_count('comment'); // Checking if there are any actual comments (trackbacks and pingbacks excluded)

if ($comNo == 1 ) {
?>
<span class="postComments"><?php comments_popup_link('Add your comment', 'Read 1 comment', 'Read '.$comNo.' comment'); ?></span>
<?php }
elseif ($comNo > 1) {
?>
<span class="postComments"><?php comments_popup_link('Add your comment', 'Read 1 comment', 'Read '.$comNo.' comments'); ?></span>
<?php }
else {
?>
<span class="postComments"><?php comments_popup_link('Add your comment', 'Add your comment', 'Add your comment'); ?></span>
<?php } ?>
Gracias de nuevo!