Pregunta

Estoy haciendo mi propia plantilla comentario ( como esto ) y necesito saber cómo puedo obtener el comentario y de ping recuento para el puesto actual, tal vez mediante una consulta de base de datos rápida o algo por el estilo?

Tenga en cuenta que no puedo usar count($comments) ni nada de eso, porque no voy a ejecutar la función comments_template() por defecto que se lleva todos los comentarios de la base de datos. En vez estoy tirando sólo el más reciente 10 comentarios usando get_comments().

$post->comment_count (aparentemente inicializado por get_post ) está cerca de lo que estoy buscando, pero cuenta tanto los comentarios como los pings: (

¿Fue útil?

Solución

Puede utilizar esta función personalizada en el functions.php del tema:

/**
 * count for trackback, pingback, comment, pings
 *
 * embed like this:
 * fb_comment_type_count('pings');
 * fb_comment_type_count('comment');
 */
if ( !function_exists('fb_comment_type_count') ) {
        function fb_get_comment_type_count( $type='all', $zero = false, $one = false, $more = false, $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);
                        fb_update_comment_type_cache($p);
                }
                ;
                if ( $type == 'pingback' || $type == 'trackback' || $type == 'comment' )
                        $count = $cjd_comment_count_cache[$post_id][$type];
                elseif ( $type == 'pings' )
                        $count = $cjd_comment_count_cache[$post_id]['pingback'] + $cjd_comment_count_cache[$post_id]['trackback'];
                else
                        $count = array_sum((array) $cjd_comment_count_cache[$post_id]);

                return apply_filters('fb_get_comment_type_count', $count);
        }

        // comment, trackback, pingback, pings, all
        function fb_comment_type_count( $type='all', $zero = false, $one = false, $more = false, $post_id = 0 ) {

                $number = fb_get_comment_type_count( $type, $zero, $one, $more, $post_id );
                if ($type == 'all') {
                        $type_string_single = __('Kommentar', FB_BASIS_TEXTDOMAIN);
                        $type_string_plural = __('Kommentare', FB_BASIS_TEXTDOMAIN);
                } elseif ($type == 'pings') {
                        $type_string_single = __('Ping und Trackback', FB_BASIS_TEXTDOMAIN);
                        $type_string_plural = __('Pings und Trackbacks', FB_BASIS_TEXTDOMAIN);
                } elseif ($type == 'pingback') {
                        $type_string_single = __('Pingback', FB_BASIS_TEXTDOMAIN);
                        $type_string_plural = __('Pingbacks', FB_BASIS_TEXTDOMAIN);
                } elseif ($type == 'trackback') {
                        $type_string_single = __('Trackback', FB_BASIS_TEXTDOMAIN);
                        $type_string_plural = __('Trackbacks', FB_BASIS_TEXTDOMAIN);
                } elseif ($type == 'comment') {
                        $type_string_single = __('Kommentar', FB_BASIS_TEXTDOMAIN);
                        $type_string_plural = __('Kommentare', FB_BASIS_TEXTDOMAIN);
                }

                if ( $number > 1 )
                        $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('%', FB_BASIS_TEXTDOMAIN) . ' ' . $type_string_plural : $more);
                elseif ( $number == 0 )
                        $output = ( false === $zero ) ? __('Keine', FB_BASIS_TEXTDOMAIN) . ' ' . $type_string_plural : $zero;
                else // must be one
                        $output = ( false === $one ) ? __('Ein', FB_BASIS_TEXTDOMAIN) . ' ' . $type_string_single : $one;

                echo apply_filters('fb_comment_type_count', $output, $number);
        }
}

Esta función le dan la cuenta de pingback, vínculo de referencia, comentarios o todos, ejemplo:

<h2 class="comments"><?php fb_comment_type_count( 'comment' ); ?></h2>

puede utilizar el parámetro de seguimiento para el retorno del mostrador: comentario, trackback, pingback, pings o toda

Licenciado bajo: CC-BY-SA con atribución
scroll top