WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Second Loop not displaying all posts (3 posts)

  1. daboo
    Member
    Posted 2 years ago #

    Hey all. I have a secondary loop on some of my pages displaying posts of a specific category. This loop is currently displaying 10 of 18 posts in this category, and I can't figure out why. There is a counter in the loop to wrap each five posts in a div, but so far it isn't displaying more than two divs. Code for the secondary loop:

    query_posts('cat=8'); /* cat with 18 posts */
    $counter = 1;
    if (have_posts()) :
    	while (have_posts()) : the_post();
    	if ($counter == 1) { echo '<div class="licont" style="float:left;">'; } ?>
    		<div>
    			<span class="icon_sprite year_icon year_<?php echo the_time('Y'); ?>"></span>
    			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('thumbnail') ?></a><br />
    			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    				<?php echo substr(preg_replace('/([^>]*)(\,|:)([^>]*)/', '$1', get_the_title()), 0, 21); ?>
    			</a>
    		</div>
    		<?php if ($counter == 5) { echo '</div>'; $counter = 1; } else { $counter++; } ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    Does anyone more familiar with the loop (or php) see where I went wrong? Presently this loop displays the ten most recently posts chronologically. Changing the dates of the posts does change which posts are displayed, but not the number which are displayed. Thanks in advance

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    if you don't specify the number of posts, the number is possibly taken from the reading settings in the dashboard;

    try:

    query_posts('cat=8&posts_per_page=-1'); /* cat with 18 posts */

    http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

  3. daboo
    Member
    Posted 2 years ago #

    Dear Sir,
    You are a very clever man. I don't know why that hadn't crossed my mind, but that was exactly the problem. Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic