Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this custom loop:

<?php // Display the top ones
    $args = array(
        'post_type' => 'reply',
        'post_parent' => $post->ID,
        'r_sortby' => 'highest_rated',
        'r_orderby' => 'desc',
        'order' => 'DESC'
    );
?>


<?php query_posts( $args ); ?>

<div class="entry-list-top">

<?php while ( have_posts() ) : the_post(); ?>

    <h2 class="dark-title"><?php _e( 'Top Replies' ); ?></h2>

    <div class="topic-entry">
        <div class="topic-author">
            <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>
        </div>

        <div class="topic-content">
            <span class="topic-author-link"><?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?></span>
            <?php bbp_reply_admin_links(); ?>
            <span class="topic-post-date"><?php printf( __( '<span>%1$s</span> <span>at %2$s</span>', 'bbpress' ), get_the_date(), esc_attr( get_the_time() ) ); ?></span>
            <?php bbp_reply_content(); ?>

        <div class="tt-like-button">
            <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
        </div>

        </div>

    </div>

    <?php $most_voted[] = get_the_ID(); // get the id of the most voted post ?>

<?php endwhile; ?>

I would like to retrieve the number of posts (only in this loop). (The is another loop below).

Any suggestions?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Just count the number of returned posts of the first loop:

Replace:

<?php query_posts( $args ); ?>

With:

<?php
$posts = query_posts( $args );
$count = count($posts);
?>
share|improve this answer
    
Sorry, where should I place that code? –  janoChen Jun 28 '11 at 16:12
    
Thanks! Hope it wasn't a basic question. –  janoChen Jun 28 '11 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.