Site logo

[Resolved] Making grid with child pages

Home Forums Support [Resolved] Making grid with child pages

Home Forums Support Making grid with child pages

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #2276844
    Fernando
    Customer Support

    You’re welcome Joey! WordPress offset and pagination is a really complicated topic. Glad that worked though!

    #2289077
    Joey

    Sorry to re-open this. I have one more issue that showed up related to the above code. My categories and author pages don’t have a featured post, and because of that there is a hanging blog post at the end on those pages (I’ll put a link below to show). Is there a way to disable this on those pages (12 posts on categories and author, but 13 on the blog home)?

    In other words, the idea is that the blog home is the only place on the site with a featured post (on desktop). On other blog-related pages, it’s just a standard 3 column row for desktop. But both those pages need to have the space filled and no hanging posts. One solution is to get rid of the “More” button. But is there a way to do this and keep the “More” button?

    #2289082
    Joey

    Sorry to re-open this. I have one more issue that showed up related to the above code. My categories and author pages don’t have a featured post, and because of that there is a hanging blog post at the end on those pages (I’ll put a link below to show). Is there a way to make 12 posts on categories and author, but 13 on the blog home?

    In other words, the idea is that the blog home is the only place on the site with a featured post (on desktop). On other blog-related pages, it’s just a standard 3 column row. But both those pages need to have the space filled and no hanging posts.

    Edit: Maybe it would be easier with a Block Element. I’m going to try that first.

    #2289116
    Fernando
    Customer Support

    Hi Joey,

    I see. Try adding this PHP:

    function set_posts_per_page( $query ){
        if( ! is_admin() && ! $query->is_home() && $query->is_main_query() ){
                $query->set( 'posts_per_page', 12 );
        }
    }
    add_action( 'pre_get_posts', 'set_posts_per_page' );

    This would set all other archives to show 12 posts per page except for the blog/home page.

    Kindly let us know how it goes.

    #2289978
    Joey

    Thank you Fernando, that works.

    Where can I find the Block Element ID, if I want to do this with a Block Element Hook? I’m looking in the inspector, but not sure which is the ID.

    #2290045
    Ying
    Staff
    Customer Support

    The element ID will show in the URL when you are at the element’s editor, for example:
    https://www.screencast.com/t/dAWIhzDpo

    #2290203
    Joey

    Oh, the post ID? But doesn’t each post have a unique ID? In other words, if I want to remove the featured post with Fernando’s code and replace it with a block element, I would have to change the code every time I have a new featured post?

    Fernando’s original solution worked (just using PHP, not a block element), so no big deal. I’m just curios about how to do it with Block Elements, in case I need to add more content to the top of the page. Thanks a lot.

    #2290230
    Fernando
    Customer Support

    That’s correct. The post ID in the URL while editing the Element is also the Element ID as shown in Ying’s screenshot.

    If you plan to add more content to the top of the page, the second code would still work, you would just need to modify it.

    If you wish to use the first suggested way, you need to alter the code as well depending on how many posts you’re going to put on top.

    #2290251
    Joey

    Okay, I understand. So the Block Element ID is just the post ID. My idea was to have the most recent post as automatically featured. As is though, it’s working well, so I’ll just leave it and come back to the Block Element when I need to add more content. I understand much better how it works now—thanks a lot to both of you for all your help.

    #2290255
    Fernando
    Customer Support

    You’re welcome Joey!

Viewing 10 posts - 16 through 25 (of 25 total)
  • You must be logged in to reply to this topic.