• Hello i need some help from theme developer, i have a posts loop command here it is :

    <?php 
    
          if(have_posts()) :
          	while (have_posts()) : the_post(); ?>
    
          	<h2><?php the_title(); ?></h2>
          	<p><?php the_content();?></p>
          	<?php the_post_thumbnail(); ?>
    
          	<?php
          	 endwhile;
          	else:
          		echo '<p>Sorry, nothing found here</p>';
    
          	     endif;
             ?>

    i have sum total of 10 posts , now my front page displays 10 out of 10 posts , but i just want it to display only 5 out of 10 posts, the latest 5 that i posted, also i want to display them horizontally as well as vertically in boxes so that it just fits in the page nicely. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • To change the number of post to be shown you will need to access to your WordPress dashboard and then settings>discussion there you will see “Blog pages show at most” change it to the number you want.

    Now to answer your second questions, it seems to be just a css solution. If you just Bootstrap then you can use the nested grid classes, something like:

    <div class="col-md-12">
    <div class="col-md-4">
    Some content
    </div>
    </div>
    

    Sorry I completely misunderstood your question.
    What you want is to show the recent posts in your front-page.php, right?

    In that case you can do so by doing this:

    
    <?php $postslist = get_posts('numberposts=5&order=DESC'); foreach ($postslist as $post) : setup_postdata($post); ?>
    
          	<h2><?php the_title(); ?></h2>
          	<p><?php the_content();?></p>
          	<?php the_post_thumbnail(); ?>
    
    <?php endforeach; ?>
    

    You dont really need to use the loop(or a custom wp query) if you just want to show the latest posts and because is the front-page.

    Hope it helps

    • This reply was modified 3 years, 6 months ago by kirasiris.

    Hello,
    You can use below code. I guess this will match your need.

    
    // The Query
        $args = array(
            'post_status' => 'publish',
            'posts_per_page'=>5,
            'order'=>'DESC',
            'orderby'=>'ID',
        );
    
        $the_query = new WP_Query( $args );
    
        // The Loop
        if ( $the_query->have_posts() ):
            while ( $the_query->have_posts() ):
                $the_query->the_post();
                ?>
                <div class="col-md-4">
                 
    				<h2><?php the_title(); ?></h2>
    		      	<p><?php the_content();?></p>
    		      	<p><?php the_post_thumbnail(); ?></p>
                	 
                </div>
                <?php
                //your html here for latest 2
            endwhile;
    		wp_reset_postdata();
        else:
            // no posts found
            echo '<p>Sorry, nothing found here</p>';
        endif;
    

    You can change bootstrap class from code.
    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loop problem’ is closed to new replies.