Number of blogposts on page

Community Forums Forums Design Tips and Tricks Number of blogposts on page

This topic is: resolved

This topic contains 6 replies, has 3 voices, and was last updated by  Jared Williams 1 year, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #29665

    normanviss
    Participant
    Post count: 27

    I am using Education theme.

    I would like only one blogpost on the Home Page – the most recent one.

    Then when a visitor clicks on ‘older posts’, I’d like them to see a list of posts (5 or 6) instead of just one.

    Can anyone give me a tip on how to do that?

    Thx!

    My url is: http://expateverydaysupportcenter.com/

    #29679

    Jared Williams
    Participant
    Post count: 47

    This can be done but will require some mods to your functions.php file.

    In your functions.php file you need to add this code that was adapted from Bill Erickson’s post on Customizing The WordPress Query

    [php]add_action( ‘pre_get_posts’, ‘be_change_event_posts_per_page’ );
    /**
    * Change Posts Per Page for Event Archive
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/customize-the-wordpress-query/
    * @param object $query data
    *
    */
    function be_change_event_posts_per_page( $query ) {

    if( $query->is_main_query() && !is_admin() && $query->is_home() ) {
    $query->set( ‘posts_per_page’, ’1′ );
    }

    }[/php]

    You see this line:

    [php]$query->set( ‘posts_per_page’, ’1′ );[/php]

    ’1′ is saying that we want 1 post to show on the home page. If you wanted 6, you would change the number.

    You will then need to go into your Settings –> Reading and select the number of posts you would like to show up on the following pages. It defaults to 10.

    I have tested this on an install of Education and it works.

    Hope this helps!


    #29689

    normanviss
    Participant
    Post count: 27

    Thanks, Jared,

    I added this code to functions.php (at the bottom)

    and now the site doesn’t work at all . I removed the code, and the site still doesn’t work.

    Ideas?

    [php]

    add_action( ‘pre_get_posts’, ‘be_change_event_posts_per_page’ );
    /**
    * Change Posts Per Page for Event Archive
    *
    * @author Bill Erickson
    * @link <a href="http://www.billerickson.net/customize-the-wordpress-query/&quot; rel="nofollow">http://www.billerickson.net/customize-the-wordpress-query/</a&gt;
    * @param object $query data
    *
    */
    function be_change_event_posts_per_page( $query ) {

    if( $query->is_main_query() && !is_admin() && $query->is_home() ) {
    $query->set( ‘posts_per_page’, ’1′ );
    }

    }
    [/php]

    #29695

    normanviss
    Participant
    Post count: 27

    OK.

    I removed that piece from the ftp files, so the site is up again.

    But I must be doing something wrong.

    Any suggestions are welcome.

    Thx!

    #29720

    Susan
    Moderator
    Post count: 9011

    Have you tried Bill Erickson’s Grid Loop plugin? You can customize how many features and excerpts appear on the front page, and on internal pages. I have just done it with a site I’m working on – my home page has one excerpt, and the internal pages have 6 excerpts each.


    Susan @ Graphically Designing I offer theme customizations I tweet!
    I’ve taken up the challenge! – help me answer some of the unanswered posts

    #29734

    normanviss
    Participant
    Post count: 27

    Thanks Susan – works great!

     

    Norman

    #29933

    Jared Williams
    Participant
    Post count: 47

    Sorry that did not work out for you. I’m not sure what the issue was since I tested on an install of Education. Glad you found Bill’s other solution!


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.