[Resolved] Different number of post in first page of blog and Elementor

Home Forums Support [Resolved] Different number of post in first page of blog and Elementor

Home Forums Support Different number of post in first page of blog and Elementor

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #941061
    Diogenes

    Hi.

    Apply the code that is put in this post: https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/#post-372928 and it works great in the blog.

    But since I have a homepage made with Elementor and a post grid widget, apparently this code affected the quantities shown on this page with the widget, which is set to show only three; but the amount set in the code is shown, which is 9.

    I’d appreciate your help.

    Thanks in advance.

    P.D. For now remove the code from the page on the page waiting for your help.

    #941066
    Leo
    Staff
    Customer Support

    Hi there,

    Can you try this instead?

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( $query ) {
        if ( ! is_main_query() && ! is_front_page() ) {
            return;
        }
    
        if ( ! $query->is_paged && ! is_front_page() ) {
            $query->set( 'posts_per_page', 10 );
        }
    }

    Let me know πŸ™‚

    #941504
    Diogenes

    I work perfect!
    Thanks Leo.

    #942014
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

    #957065
    Diogenes

    Hi.

    Excuse me for reliving this post, but after a few weeks I realized that this function that Leo gave me, affects the way the wordpress media library is displayed.

    To be more precise, only the last images that I have loaded (last 9) in it are shown in the media library, sorted by grid.

    All others are not displayed.

    When I disable the function in the functions.php, everything returns to normal and you can see them all in the wordpress image gallery.

    However when I order them by list (media library) they are all displayed correctly.

    Can you help me please,

    Thank you.

    P.D. I just realized that it also affects the pages that are displayed in the wordpress backend: Pages> All pages. They only show 9

    #957135
    Leo
    Staff
    Customer Support

    Hmm not sure how that code can affect something in the media library.

    I did notice a syntax error in my code and fixed it. Can you give it another shot?
    https://generatepress.com/forums/topic/different-number-of-post-in-first-page-of-blog-and-elementor/#post-941066

    #957144
    Diogenes

    Leo does not work πŸ™

    #957150
    Leo
    Staff
    Customer Support

    I really don’t see how that snippet has anything to do with the media library.

    Have you tried disabling all plugins to make sure it’s not a plugin conflicts somewhere?

    #957156
    Diogenes

    Yes Leo, I already did it. I have since yesterday looking for the solution of that error, in fact, I did not initially think it was due to this code that you passed me.

    So I had disabled all the plugins, and enabled them one by one, reinstall the wordpress, forced the regeneration of all the images, verify the permission of the images on the server, among many other things.

    By chance, by a post in wordpress of someone who commented on a problem simulated by a code in functions.php is that I remembered this code, and to disable it, voila, everything worked fine.

    It must be related, since I substitute the number 10 of the code, for 9, which are the post I want on each page apart from the initial of the blog; and this same number are the images that I can see in the media library with the active code (with the grid), as well as the pages I mentioned before.

    #957599
    Tom
    Lead Developer
    Lead Developer

    Try this:

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( $query ) {
        if ( ( ! is_main_query() && ! is_front_page() ) || is_admin() ) {
            return;
        }
    
        if ( ! $query->is_paged && ! is_front_page() ) {
            $query->set( 'posts_per_page', 10 );
        }
    }

    Let me know πŸ™‚

    #957631
    Diogenes

    I work perfect Tom.

    Thanks for the help πŸ™‚

    #957863
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #1056724
    Matias

    Hi, Im using that code to show different number of post in home and in archives pages but when I active this code using Code Snippets, Yoast Breadcumbs doesnt show

    #1057110
    Leo
    Staff
    Customer Support

    Can you link us to the page in question?

    Feel free to open a new topic if you want to use the private URL field.

    #1057138
    Matias
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.