- This topic has 24 replies, 4 voices, and was last updated 3 years, 10 months ago by
Fernando.
-
AuthorPosts
-
July 8, 2022 at 12:28 am #2276844
Fernando Customer Support
You’re welcome Joey! WordPress offset and pagination is a really complicated topic. Glad that worked though!
July 20, 2022 at 8:45 pm #2289077Joey
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?
July 20, 2022 at 8:49 pm #2289082Joey
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.
July 20, 2022 at 10:03 pm #2289116Fernando 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.
July 21, 2022 at 12:58 pm #2289978Joey
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.
July 21, 2022 at 3:21 pm #2290045Ying
StaffCustomer SupportThe element ID will show in the URL when you are at the element’s editor, for example:
https://www.screencast.com/t/dAWIhzDpoJuly 21, 2022 at 9:14 pm #2290203Joey
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.
July 21, 2022 at 10:18 pm #2290230Fernando 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.
July 21, 2022 at 10:58 pm #2290251Joey
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.
July 21, 2022 at 11:10 pm #2290255Fernando Customer Support
You’re welcome Joey!
-
AuthorPosts
- You must be logged in to reply to this topic.