Only show one Post on front page

  • Mango

    #6279

    Greetings,

    All good with Graphene Theme. I am just wondering if its possible to show one full (latest) Post on Front (Home) page? And use the Default setting everywhere else.

    My site is at http://celvin.com.au

    Thanks,

    Mango

    Prasanna SP

    #33883

    See this post – http://www.prasannasp.net/wordpress-change-number-of-posts-on-archive-page/

    To show only one post on homepage, change

    if ($query->is_archive)

    to

    if ($query->is_home)

    Mango

    #33884

    Greetings Prasanna,

    Thank you for your reply. My Graphene Child functions.php now looks like this:

    <?php
    function number_of_posts_on_archive($query){
    if ($query->is_home) {
    $query->set('posts_per_page', 1);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');
    ?>

    However I still get the default number of Posts (3) on Home page?

    Can you think what I am doing wrong?

    I am using Graphene 1.82

    Thanking you,

    Mango

    Prasanna SP

    #33885

    Try setting number of posts on homepage to 1 in Reading Settings and use the below code to change number of posts on archives to 3

    <?php
    function number_of_posts_on_archive($query){
    if ($query->is_archive) {
    $query->set('posts_per_page', 3);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');
    ?>

    Put code in between backtick (

    Code:
    `

    ) characters here. It’s usually located above the Tab key on your keyboard.

    Mango

    #33886

    Hi Prasanna,

    I have tried those settings, Reading Settings = 1, and function.php using your code results in 3 Posts in Archive and on Home Page. It appears that whatever is specified in the Child Theme functions.php overrides Reading Settings.

    It seems not possible to do this.

    Thank you for trying to help.

    Mango

    Prasanna SP

    #33887

    Keeping number of posts on homepage to 1, try this,

    <?php
    function number_of_posts_on_archive($query){
    if ($query-> is_archive() || !is_home() ) {
    $query->set('posts_per_page', 3);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');
    ?>

    Mango

    #33888

    Still the same unfortunately Prasanna. Whatever number is set in the functions.php code, in this case 3, determines the number of Posts on the Home Page and Archive Pages.

    For example if I change functions.php posts per page number to 2 then 2 Posts will be displayed on Home and Archive Pages.

    Thanks for trying.

    Mango

    #33889

    Good morning Prasanna,

    This code works in limiting the Posts on the Home Page to 1, but of course it also limits Category queries to 1 and as such is unusable for my purpose. For some reason the Home Page thinks that it is a Category?

    <?php
    function number_of_posts_on_archive($query){
    if ($query->is_category) {
    $query->set('posts_per_page', 1);
    }
    return $query;
    }

    add_filter('pre_get_posts', 'number_of_posts_on_archive');
    ?>

    Regards,

    Mango

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

You must be logged in to reply to this topic.