WordPress.org

Ready to get started?Download WordPress

Forums

Why is archive.php displays all post, not only month (4 posts)

  1. jonas18z
    Member
    Posted 1 year ago #

    I have a archive page that I display with:

    <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>

    But when press on a link it's shows all post in 'may' for example, it show all post from every month:

    Here is get post from my archive.php

    <?php
    $args = array( 'numberposts' => 99 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    
    <!-- Start post -->
    
                				<div class="top_news">	
    
                    <img src="<?php echo get_post_meta($post->ID, 'news_first_image', true); ?>"/>
    				<?php } ?>
    				</div>
    
    				<h2><?php the_title(); ?></h2>
    				<p>
    					<?php the_content(); ?>
    				</p>
    
    			<!-- End Post -->
    
    <?php endforeach; ?>   
    
    </div>

    Anyone know what the problem is?

  2. jonas18z
    Member
    Posted 1 year ago #

    Sorry for bump, but I still have this problem. What do I missing?

  3. Chip Bennett
    Theme Review Admin
    Posted 1 year ago #

    Try getting rid of the custom query (i.e. get_posts() ) and just use the normal loop:

    if ( have_posts() ) : while ( have_posts() ) : the_post();
        // Loop markup here
    endwhile; endif;

    The problem is your custom loop is stomping the normal query that WordPress is attempting to use, and it is that normal query that knows to display only posts from the given month.

    You're telling WordPress, "Don't use the query you want to use; use my custom query instead."

  4. jonas18z
    Member
    Posted 1 year ago #

    Works!! thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic