<!-- Approch-1 : open sidebar.php file & c-P form index.php file --> <!-- Approch-2 : remove pagination code and remain the limit to 3 --> <!-- Approch-3 : change sql queries as per requirment --> <div id="sidebar" class="col-md-4"> <!-- search box --> <div class="search-box-container"> <h4>Search</h4> <form class="search-post" action="search.php" method ="GET"> <div class="input-group"> <input type="text" name="search" class="form-control" placeholder="Search ....."> <span class="input-group-btn"> <button type="submit" class="btn btn-danger">Search</button> </span> </div> </form> </div> <!-- /search box --> <!-- recent posts box --> <div class="recent-post-container"> <h4>Recent Posts</h4> <?PHP /*-- Step-2: copy pagination calculation code form post.php file --> */ include "config.php"; $limit = 3; /*-- Step-3: copy sql command form post.php and add image query code --> */ $sql = "SELECT post.post_id, post.title, post.post_date, category.category_name, post.category,post.post_img FROM post LEFT JOIN category ON post.category = category.category_id ORDER BY post.post_id DESC LIMIT {$limit}"; /*-- Step-4: c-p sql run query form post.php file --> */ $result = mysqli_query($conn, $sql) or die("Query Failed.: Recent Post "); if(mysqli_num_rows($result) > 0){ /*-- Step-5: c-p while loop code form post.php file --> */ while($row = mysqli_fetch_assoc($result)) { ?> <div class="recent-post"> <a class="post-img" href="single.php?id=<?php echo $row['post_id']; ?>"> <img src="admin/upload/<?php echo $row['post_img']; ?>" alt=""/> </a> <div class="post-content"> <h5><a href="single.php?id=<?php echo $row['post_id']; ?>"><?php echo $row['title']; ?></a></h5> <span> <i class="fa fa-tags" aria-hidden="true"></i> <a href='category.php?cid=<?php echo $row['category']; ?>'><?php echo $row['category_name']; ?></a> </span> <span> <i class="fa fa-calendar" aria-hidden="true"></i> <?php echo $row['post_date']; ?> </span> <a class="read-more" href="single.php?id=<?php echo $row['post_id']; ?>">read more</a> </div> </div> <?PHP } } ?> </div> <!-- /recent posts box --> </div>