• Resolved lucipublishing

    (@lucipublishing)


    Hey everyone,

    I was wondering if someone had the code handy for just showing 4 posts on the main page, NOT 4 posts on everypage, just the main page. From what I can gather from the Loop editing posts prior to this one, I haven’t seen the proper syntax for just showing a certain number. Any threads or URLs would be fine if anyone has those handy.

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Maybe it is not the best idea – unless you know for sure your index.php file is NOT used to display anything else than the main page.
    Index.php is the default fallback for anymissing template file, so editing it might affect more than just your main/home page.

    If you are uncomfortable messing with the code – I’d suggest using a plugin CQS = custom query string; you can set with it the number of posts shown for every view: index, archives, month, catgeory, search etc.

    Thread Starter lucipublishing

    (@lucipublishing)

    moshu,

    Thanks for the reply. This is actually for a new client install, and I really don’t want to hard code anything, will CQS make sure that only 4 posts will show up?

    They want just 4 posts to show, and a previous coder installed a category excluder which works fine, I just need to make sure that they get what they want with just the four showing.

    Thanks!

    I also work for clients sometimes… but when I need help I don’t ask here for free support – I contact knowledgeable coders and pay them.

    hey! if yer still looking for the answer (according to version 2.2.2) here it is, just replace in yer index.php

    these lines

    <?php if (have_posts()) : ?>
      <?php while (have_posts()) : the_post(); ?>

    for

    <?php $top_query = new WP_Query('showposts=4'); ?>
      <?php if(have_posts()) : ?>
        <?php while($top_query->have_posts()) : $top_query->the_post(); $first_post = $post->ID; ?>

    well this work only for the 4 last posts published!

    synth>>

    this is perfect, and just what i’m looking for.

    I need to show only the latest post from 2 different categories on my front page.
    However, this only works for one of the categories. Prolly because i just copy the query later on in the page right..?

    I’m sure its possible to get by it by renaming the right functions, im just no php-man.. Can you help me out?

    Regards, Rasmus Landgreen

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Number of posts on a page — Editing the Loop’ is closed to new replies.