WordPress.org

Ready to get started?Download WordPress

Forums

show only X number of posts (9 posts)

  1. Anonymous
    Unregistered
    Posted 9 years ago #

    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(); ?>
    <td>
    <h4 id="post-<?php the_ID(); ?>"><?php the_time("d/m/y"); ?> - <?php the_title(); ?></h4>
    <?php
    if ($single) {
    the_content();
    }
    else {
    the_excerpt();
    }
    ?>

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

  2. Beel
    Member
    Posted 9 years ago #

    in the options

  3. Anonymous
    Unregistered
    Posted 9 years ago #

    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 ! */
    $blog=1;
    $cat= 3;
    require_once("./wordpress/wp-blog-header.php");
    ?>
    <!-- // 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"); ?>
    </div>
    <!-- // 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.

  4. Anonymous
    Unregistered
    Posted 9 years ago #

    please?

  5. francesca
    Member
    Posted 9 years ago #

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

  6. TechGnome
    Moderator
    Posted 9 years ago #

    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...
    TG

  7. francesca
    Member
    Posted 9 years ago #

    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...

  8. TechGnome
    Moderator
    Posted 9 years ago #

    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.)
    TG

  9. Anonymous
    Unregistered
    Posted 9 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.