Limiting Number of Posts (4 posts)

  1. thewatcher
    Posted 10 years ago #

    Hi all,
    I'm having some problems with limiting how many posts I see in a particualr place. There's lots of discussion on the forums and in other places about it but thus far nothing I've tried has worked.
    What I'm doing is as follows.
    Wordpress is running as a "news blog" on http://example.com/news/ but I want particular articles to appear in a small section of the main page at http://example.com/
    I extracted the pre-requisite parts from the standard WP index and put them on the main page in the place where I wanted them and everything displays wonderfully, except when I try to limit the number of posts appearing on the sites main page. Nothing seems to work.

    <?php get_calendar(); ?>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <h3>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></h3>
    <?php the_time("d M y @ H:i"); ?>
    <?php the_content();
    endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    Above are the bits I extracted from the standard index page and included on the main page to display everything. I've thus far tries all the variants of limiting posts that I can find but with no success.
    Any help or guidance appreciated. Do I need to include more of the WP code on the sites main page to get hte limiting to work?

  2. moshu
    Posted 10 years ago #

    Did you see thise one?

  3. thewatcher
    Posted 10 years ago #

    I'd seen that as part of some solution that I tried that didn't work. Gave it a stab again. Didn't work.
    This is what I tried.

    <?php $posts = get_posts('numberofposts=2'); ?>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

    or does that require hacking on the loop or something like that?

  4. I use the following to list the last n posts, where is n is the number of posts I want shown:
    <?php wp_get_archives('type=postbypost&limit=n'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.