WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show less posts on front page (13 posts)

  1. Christopher Roberts
    Member
    Posted 3 years ago #

    I am a bit of a newby to PHP, and I don't really get it. I can HTML code ok, but I am not any good at PHP.

    Is there any simple way that I can get my homepage to show two articles and all other pages to show 7?

    I have tried the plugin http://wordpress.org/extend/plugins/set-front-page-post-count/ but it really mucked up the page structure navigation, so that is a no no :-(

    Site is called Technology Bloggers in case you were interested :-)

    All help valued
    Thanks!
    Christopher

  2. evandunn
    Member
    Posted 3 years ago #

    On your front page template, you can add an iteration count.
    Before the loop set: $i = 0;
    Then inside the loop add

    if ($i <= [here add the number of posts]){
    [your normal frontpage content]
    $i++;
    }
  3. Christopher Roberts
    Member
    Posted 3 years ago #

    Thanks for the reply, evandunn, but being a PHP 'fool' I don't know what that means :-P
    What file do I need to go to, and where do I put it...

    Sorry for being so naive!

    Christopher

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Set the posts per page on Settings-> Reading to 7. Then add something like:

    <?php
    if( is_home() && !is_paged() ) :
    global $query_string;
    query_posts( $query_string . '&posts_per_page=2' );
    ?>

    immediately before the start of the Loop in your theme's index.php template file.
    http://codex.wordpress.org/Function_Reference/query_posts

  5. Christopher Roberts
    Member
    Posted 3 years ago #

    Really grateful for your help, but...

    BIG error, says Parse error: syntax error, unexpected $end in /home/fhlinux150/t/technologybloggers.org/user/htdocs/wp-content/themes/twentyten/index.php on line 37

    Here is the Main Index Template (index.php) code, could you send me it how it should look please, thanks!

    [Code moderated as per the Forum Rules. Please use the pastebin]

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    Don't edit the Twenty Ten theme. Your changes will be over-written the next time you upgrade WordPress. For this reason, it is recommended that you consider creating a child theme for your customisations. Once your child theme is active, we should be able to help with the customisation.

  7. Christopher Roberts
    Member
    Posted 3 years ago #

    k will investigate, thanks :-)

  8. Christopher Roberts
    Member
    Posted 3 years ago #

    Tried to do a child theme, but it didn't seem to work :-/
    Created a normal theme, just by duplicating the original theme, but it still returns error Parse error: syntax error, unexpected $end in /home/fhlinux150/t/technologybloggers.org/user/htdocs/wp-content/themes/twentyten-custom/index.php on line 37 when I put

    <?php
    if( is_home() && !is_paged() ) :
    global $query_string;
    query_posts( $query_string . '&posts_per_page=2' );
    ?>

    just before

    <?php
    			/* Run the loop to output the posts.
    			 * If you want to overload this in a child theme then include a file
    			 * called loop-index.php and that will be used instead.
    			 */
    			 get_template_part( 'loop', 'index' );
    			?>
  9. esmi
    Forum Moderator
    Posted 3 years ago #

    Sorry - my bad. Use:

    <?php
    if( is_home() && !is_paged() ) :
    global $query_string;
    query_posts( $query_string . '&posts_per_page=2' );
    endif;
    ?>
  10. Christopher Roberts
    Member
    Posted 3 years ago #

    @esmi U R a genius!!!!!

    Thank you very much :-)

  11. Adam Harley
    Member
    Posted 3 years ago #

    Author of Set Front Page Post Count here, just want to point that using query_posts() and posts_per_page on the homepage to override the normal posts_per_page value does have unintended consequences. WordPress will assume the homepage still had the normal post count and not display the first X posts (where X is the normal per-page setting), even if the front page only had 2, so you end up losing posts 3-X.

  12. Christopher Roberts
    Member
    Posted 3 years ago #

    @Adam I see what you mean :-/

    How can I quickly 'download' all of my settings so that you can replicate the blog? i.e. plugins, themes etc.

  13. Adam Harley
    Member
    Posted 3 years ago #

    Easiest way would probably still involve dumping one or more of the database tables and the site files.

    Can you try disabling your current plugins and reverting back to stock Twenty Ten, then work backwards from there? That should rule out any conflicts.

Topic Closed

This topic has been closed to new replies.

About this Topic