Site logo

Archived topic

Making grid with child pages

24 replies · Started by Joey on July 3, 2022

Viewing posts 16–25 of 25

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

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?

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.

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.

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.

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.

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.

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.

You’re welcome Joey!

This archived topic is closed to new replies.