Thursday 30 June 2016

WordPress Tutorial - Listing Blog Posts in Different Style with blog count

Previous Video: https://youtu.be/x3HVk2PuUSA
Previous Text: http://1wmedia.blogspot.in/2016/06/listing-blog-posts-in-different-style.html

In this tutorial, We will correct the previous bugs in the code and displaying limited post lists, I mean 5 or 7 latest posts. Please view the previous tutorial before reading this tutorial.

  1. Open your front-page.php file and remove the unwanted <hr> tags. 
  2. Add if statement for count which is the post count less than or equal to 5.

    <?php if ($count <= 5) : ?>
  3. close the if statement before the endwhile.
  4. Save the file. Now view the site. You will see only 5 posts in the post area.
  5. For Post Thumbnail, Go to Post Edit and add thumbnail. For thumbnail size, Please view the previous tutorial.
Here is the modified code:

   <!-- START THE FEATURETTES -->


 <?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count <= 7) : ?>
<?php if ($count % 2 == 0) : ?>

      <div class="row featurette">
        <div class="col-md-7">
          <h2 class="featurette-heading"><?php the_title(); ?></span></h2>
          <p class="lead"><?php the_content(); ?></p>
        </div>
        <div class="col-md-5">
           <?php the_post_thumbnail('', array('class' => 'featurette-image img-responsive center-block')); ?>
        </div>
      </div>
     
      <?php else  : ?>     
 

      <hr class="featurette-divider">

      <div class="row featurette">
        <div class="col-md-7 col-md-push-5">
          <h2 class="featurette-heading"><?php the_title(); ?></span></h2>
          <p class="lead"><?php the_content(); ?></p>
        </div>
        <div class="col-md-5 col-md-pull-7">
       
           <?php the_post_thumbnail('', array('class' => 'featurette-image img-responsive center-block')); ?>
    
        </div>
      </div>
     
      
      <hr class="featurette-divider">
      <?php endif; ?>
      <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
 

      <!-- /END THE FEATURETTES -->


Video Tutorial:

 

No comments:

Post a Comment