Trying to limit post count shown
-
Hello:
I have a multicolumn archive page for a particular category (category 3):
http://testing001.compoundeyedesign.com/index.php/category/news/I am trying to show only 5 posts per column but it’s actually showing 10. Because of this error, you get some repeated posts. Ignore the rightmost column — that’s a sidebar.
I’ve looked at the code and I can’t figure out why it’s not working. Here’s the loop shown in the first column:
<!-- column 1 --> <div class="col-md-4 col-lg-3 right-trim"> <?php //YOU'LL NEED THIS ENTIRE CODE BLOCK FOR ANOTHER TEMPLATE //declares that the variable $myOffset has a global scope global $myOffset; //sets the value of the variable $myOffset $myOffset = 0; //creates a variable $temp that has the value of the $wp_query $temp = $wp_query; //states that $wp_query is null, so we can use that variable again to create our new query. this is what WP uses in the normal loop //if not set to null, WP gets very confused $wp_query= null; //recreates the $wp_query variable with a new query $wp_query = new WP_Query(); //add the posts to the $wp_query variable. the offset is how many posts should be skipped before displaying the content //so the offset= the value of $myOffset, in this case 0 (but that changes for the next loop) then show category 6 , the press release //category, then show 5 posts. The last bit is for the pagination. // To show another category instead, just change 6 to the category ID you want to use. $wp_query->query('offset=' . $myOffset . '&cat=3&showposts=5'.'&paged='.'$paged'); //this is the custom loop while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <!--This shows the post title as an H3 link--> <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <!--this shows the post content. you could use the_excerpt() instead. this shows the first 55 words of a post, but no images--> <?php the_content();?> <hr/> <?php endwhile; ?> </div><!-- column 1 -->All the annotation came from a developer who I’ve lost contact with, otherwise I’d go back to him.
The code in the next 2 columns is very similar but with
$myOffset = 5;or$myOffset = 10;.Any suggestions? I hope this isn’t too confusing.
Cheers, R
The topic ‘Trying to limit post count shown’ is closed to new replies.