Forums

[resolved] This is limiting me to 5 posts, and I don't know why (4 posts)

  1. PhilGarrett
    Member
    Posted 2 years ago #

    So I am currently using the following code in my sidebar.php file:

    <?php if (is_category(8) || in_category(8)) { ?>
        <div id="subnav">
    	<?php	$catposts=get_posts('cat=8', 'numberposts =0');
    		if ($catposts) {
    		  foreach($catposts as $post) {
    			setup_postdata($post); ?>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    		  <?php  }
    		}
    	?>
        </div>
        <?php } ?>

    It's supposed to pull the titles of all the posts in that category and list them as links. The problem is that it is limiting it to only the 5 most recent. If anyone has any idea why that might be it would be greatly appreciated.

    Thank you.

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Try

    get_posts('cat=8&showposts=-1');

  3. PhilGarrett
    Member
    Posted 2 years ago #

    Thank you very much, that worked perfectly. I realized after looking at your solution that I mis-read the codex and the use of "0" vs "-1".

    Does combining the two arguments into one make a difference as well? or is it just for shortening and/or cleaning up the code a little bit?

    Thanks again, it was greatly appreciated to get a response so quickly.

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    Actually I'm not sure the two arguments works. You can use a string of arguments as I presented or an array such as

    $args=array(
      'cat' => 8,
      'showposts' => -1
    );
    $catposts=get_posts($args);

Topic Closed

This topic has been closed to new replies.

About this Topic