• Resolved joannie

    (@joannie)


    Hi, I’m having some problems with a home-brew template. Any help would be sincerely appreciated.

    On my main blog page I have just my most recent post showing (and then a list of other posts called from outside the loop). I’ve done this by setting the number of displayed posts in the options panel to 1.

    However, now my archive page only displays 1 post at a time, and I can’t work out how to change it – I would like it to show the 10 most recent posts in a category/month etc. Is there something I can change in the loop? Are there parameters for the_post() ?

    My site is at https://www.fractalfairytales.co.uk
    Thanks in advance,
    Jo

Viewing 4 replies - 1 through 4 (of 4 total)
  • First off, you may be interested in the “Front Page” plug-in that allows you create a static front to your blog. https://www.semiologic.com/software/static-front/

    Second, yes, the loop can be changed. You’ll find this page very helpful: https://codex.www.ads-software.com/The_Loop_in_Action#Static_Front_Page

    Third, you can have one post on one page and ten on another. There are several ways to do it, and I’m not sure which will be easiest for you, personally. In any case, you’ll need to set the number of posts displayed back to ten, and then alter the loop in the index.php file that came with your template.

    The proper method is to use a query:
    https://codex.www.ads-software.com/Template_Tags/query_posts

    ?php
    get_header();
    query_posts(‘posts_per_page=1’); //returns only the front page
    ?>

    You’ll find this method well documented at:
    https://ifelse.co.uk/archives/2005/04/10/make-wp-show-only-one-post-on-the-front-page/

    The second, “quick and dirty” method is to put the one post you want on the front page in a seperate category (for example, “Front_Page”) then, filter out all other posts that aren’t in that category by adding this to your loop:

    <?php if (in_category(‘2,3,4,5)) continue; ?>

    … like this …

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

    <!– If the post is in the category we want to exclude, we simply pass to the next post. –>
    <?php if (in_category(‘2,3,4,5’)) continue; ?>

    In this example, 2,3,4,5 are the categories being filtered out of your frontpage. You can find the category numbers by going to Manage > Categories When you want to change pages, just edit the entry and change the post’s category.

    Alternatively… and I don’t know why you would do this … unless you couldn’t get a query to work and you didn’t want to change your posts’ category (for example, because of permalinks) … another method involves using a plugin, such as Tony’s Get Recent Post https://girasoli.org/?p=26. In that case you would remove your frontpage loop:

    while (have_posts()) : the_post();

    and replace it with < ?php _e(get_recent_post(0,0,0)); ?>

    That would let you display you most recent post on the frontpage, but would be really inefficient compared to the other two methods.

    Hope that helped:)

    All that is very helpful… it’s just over-complicated even for me ??
    The plugin does all that without touching one line of code!

    Thread Starter joannie

    (@joannie)

    Thank you very much – that worked a treat. I’d been coming at the problem the wrong way – trying to change the archive page and not the home page.

    I hope you have a very happy Friday.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘1 post per page on one page – 10 posts per page on another’ is closed to new replies.