Community Forums › Forums › Archived Forums › Design Tips and Tricks › Number of blogposts on page
- This topic has 6 replies, 3 voices, and was last updated 11 years ago by Jared Williams.
-
AuthorPosts
-
March 20, 2013 at 6:44 am #29665normanvissMember
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/
March 20, 2013 at 7:54 am #29679Jared WilliamsMemberThis 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
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' ); } }
You see this line:
$query->set( 'posts_per_page', '1' );
'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!
March 20, 2013 at 8:34 am #29689normanvissMemberThanks, 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?
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/" rel="nofollow">http://www.billerickson.net/customize-the-wordpress-query/</a> * @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' ); } }
March 20, 2013 at 8:43 am #29695normanvissMemberOK.
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!
March 20, 2013 at 10:37 am #29720SusanModeratorHave 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.
March 20, 2013 at 11:36 am #29734normanvissMemberThanks Susan - works great!
Norman
March 21, 2013 at 8:04 am #29933Jared WilliamsMember -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.