• Resolved lotsamottsa

    (@lotsamottsa)


    I’m trying to list subcategories and their posts within of a parent category. All is working well, but I can’t seem to get the list to show more than five posts. Here is my code:

    <?php $categories =  get_categories('child_of=3');  ?>
    		<?php foreach  ($categories as $category) { ?>
            <div class="entry-feed">
    
              <div class="entry">
              <?php echo '<h3>'.$category->name.'</h3>'; ?>
    
              <?php $args=array('cat='.$category->term_id);?>
    
              	<?php foreach (get_posts($args) as $post) {
                setup_postdata( $post );
                echo '<h3><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></h3>';
            	}//end innner for each ?></div><!--end entry feed-->
    
            <div class="clearfix"></div>
    		</div><!--end entry-->
           <?php }//end outer foreach ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • ‘5’ seems to be the number of posts per page as set under ‘settings – reading …’

    try to add the corresponding parameter to your ‘get_posts’ args;

    example:

    <?php $args=array('cat='.$category->term_id&posts_per_page=-1);?>

    ‘-1’ is for all posts; or use whatever number of posts you would like to see there.

    Thread Starter lotsamottsa

    (@lotsamottsa)

    That didn’t seem to work. My ‘reading” page is set to 99 and it is still only showing 5. Also, I am getting

    category 1
    5 posts within category 1

    category 2
    5 posts within category 1.

    This code displays the category 2 posts correctly (removed $args), but I am still only getting five posts.

    <?php $categories =  get_categories('child_of=3');  ?>
    		<?php foreach  ($categories as $category) { ?>
            <div class="entry-feed">
    
              <div class="entry">
              <?php echo '<h3>'.$category->name.'</h3>'; ?>
    
              	<?php foreach (get_posts('cat='.$category->term_id) as $post) {
                setup_postdata( $post );
                echo '<h3><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></h3>';
            	}//end innner for each ?></div><!--end entry feed-->
    
            <div class="clearfix"></div>
    		</div><!--end entry-->
           <?php }//end outer foreach ?>

    I tried:

    <?php foreach (get_posts('cat='.$category->term_id&'posts_per_page=-1') as $post) {

    but I am getting the same as above.. the wrong posts under category 2 and only five still…

    I made a typing error – corrected, try:

    <?php $args=array('cat='.$category->term_id . '&posts_per_page=-1');?>
    Thread Starter lotsamottsa

    (@lotsamottsa)

    You know for some reason it doesn’t work quite right in the variable, still showing the wrong posts for category two, but it works like this!

    <?php foreach (get_posts('cat='.$category->term_id. '&posts_per_page=-1') as $post)

    So THANK YOU SO MUCH!!!

    PS:
    there was a mixtake in my suggestion – I hadn’t looked at the $args properly;

    as you seem to try to use the array method, the line should have been:

    <?php $args = array( 'cat' => $category->term_id, 'posts_per_page' => -1); ?>

    or as string:

    <?php $args = array('cat=' . $category->term_id . '&posts_per_page=-1'); ?>
    Thread Starter lotsamottsa

    (@lotsamottsa)

    oh ok. thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘More than five posts in subcategory list’ is closed to new replies.