• Resolved Tim

    (@tim-at-fourfivexnet)


    Hi There!

    Here is a quick question that might be easy to answer for some of you:

    I want to have only one Blogpost on the frontpage / usual blog view (as it is currently seen on fourfiveX.net) but I’d like the categories to feature 10 posts per page (as it can not be seen on the site).

    I am currently using WPs standart ‘posts per page’ option.

    I was also playing around with the “query posts” function in my themes index.php:

    query_posts($_SERVER['QUERY_STRING'].'&showposts=1');

    But I get strange errors from that, since the navigation (at the bottom of the page) doesn’t seem to care about the “showposts” parameter as used above. To me (not that experienced in WP development) it seems quite a mess troughout.

    I’d love to hear suggestions, maybe even on themes that do similar stuff so I can just see how it’s done there.

    Thanks for your time,

    Tim

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use a simple “counter” to limit the amount of posts shown … see the bit of pseudo-code below that you can use in your loop:

    if (have_posts()) : while (have_posts()) : the_post();
      static $count = 0;
      if ($count == $show_count) {
        break;
      } else {
        the_content(__('Read more... '));
        $count++;
      }
      endwhile;
      else :
    endif;

    Change $show_count to whatever number you like, such as 1 and it will only show one post.

    Create/edit your category.php template file to display “normally”, and set your ‘posts per page’ to the maximum posts to display on any template.

    Hope that helps some …

    PS: The pseudo-code snippet is from one of my recent plugins and is used to limit the posts displayed by the widget.

    Thread Starter Tim

    (@tim-at-fourfivexnet)

    https://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/

    THIS seems to do the job the way I want it. Thanks for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How could I limit the number of posts in index.php ?’ is closed to new replies.