Support » Fixing WordPress » show only X number of posts

  • Hello there 🙂
    I have and index page that shows only the excerpt from the posts. It has this code: <?php foreach ($posts as $post) { start_wp(); ?>
    <h4 id="post-<?php the_ID(); ?>"><?php the_time("d/m/y"); ?> - <?php the_title(); ?></h4>
    if ($single) {
    else {

    Now, I need that only 2 posts are showed…how can I do this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • in the options

    That’s how I am using WordPress. I have a page called NEWS.php that shows all the articles with no limitation for now:
    <?php /* Don't remove this line, it calls the WP function files ! */
    $cat= 3;
    <!-- // loop start -->
    <?php foreach ($posts as $post) { start_wp(); ?>
    <div class="news">
    <h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
    <?php the_content(); ?>
    <?php the_time("d/m/y"); ?>
    <!-- // this is just the end of the motor - don't touch that line either :) -->
    <?php } ?>

    Then I have and INDEX.php with the excerpts, and I need to show only 2 excerpts…so I need to change the number of showed posts only in index.php.
    Anyway, I tried to change the option as Beel said but the pages are not affected by the change.


    I don’t understand the meaning of that code. Anyway I tried it (with 3 in place of X) and it doesn’t work 🙁

    Here’s the code translated into plainspeak:
    If the $cat variable is not set, set to 3 (the default cat you show on the main page)
    Otherwise, if the $cat is the “special” category, set the number of posts to show to 2.
    It should go at the top of your index.php, right after the $blog=1; code, and replace your $cat=3; code.
    Hmmmmm…. just tried it out. Why didn’t it work? Ack! I do know that if you add $postcount=2 to the url, it works…. wonder why not here? I bet it gets over written in wp-blog-header.php file…. grrrrr…

    Hello TG, thanx so much.
    You wrote:
    <cite>I bet it gets over written in wp-blog-header.php file…. grrrrr…</cite>
    I wonder…maybe there’s something that can be eliminated from wp-blog-header so that your code can work?
    Consider that I don’t need the general options for the number of posts to show…

    OK, this is starting to piss me off now….. can any one see why this doesn’t work:

    if ('11' == $cat) {
    $showposts = "1";

    I’ve looked through wp-blog-header.php and for the life of me, I cannot see WTF is going on. If I set $showposts explicitly, w/o regard to the category, then it works, I only get one post. But I want to only show one post IF a specific category is being viewed.
    I’ve even had the $cat printed to the title just to make sure I had the right ID. OOOhh….. wait….. CRAP!…. I think I’ve got it figured now…. ugh!
    Fransesca, let me try something out. Will get back to you on this (it’s something I could use too.)

    You wrote:
    I do know that if you add $postcount=2 to the url, it works….
    Weel, I tried but this doesn’t work for me… it would be great if I can limit the number of showed posts from the URL, it’s actually what I was looking for…
    carlo , italy

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘show only X number of posts’ is closed to new replies.