- This topic has 7 replies, 2 voices, and was last updated 3 years, 2 months ago by
Fernando.
-
AuthorPosts
-
February 8, 2023 at 11:05 am #2526296
Nancy
Hi,
I’ve been scouring through different approaches, reading documentation and I’m just not seeing a way to have a Featured Post (it’s really the latest post – we aren’t tagging it) to only show on the first page of the Blog archive.
I would hide it with CSS but I’m not sure how to do a range for the archive pages to set a “display:none”. But if I could target to have the featured post only show on the first page, that would be ideal if there is a means of targeting that in the display rules? Right now I have it set for “Blog” and attempted to exclude for “All Archives” which didn’t work :).
I have the featured post as a “Hero” block.
February 8, 2023 at 3:04 pm #2526501Nancy
I got the answer to this quandry so will share it and a big thank you to Mike Oliver.
I have the Featured Post (really the latest post) set as a hero block. On that block for “display rules” to “blog” for display. Then “Exclude” select “Paginated Results”. Be sure to clear the cache.
For the Loop template for the archive, I have that separately as a block. On that, in the Query Loop, add the Parameter to Offset “1”.
Once the cache clears it should be fine.
February 8, 2023 at 5:44 pm #2526584Fernando Customer Support
Hi Nancy,
Glad you resolved the issue! Thank you for sharing the solution as well!
February 12, 2023 at 8:36 pm #2530930Nancy
Hi Fernando,
I ended up (and thank you for answering the question in support) using “Inherit Query from Template” so I could have the nice SEO friendly pagination with page/2/ instead of page/2/?query-bbb96b2e-page=2 (yikes).
But losing the offset by 1 means a repeating article. Anyway to do that another way so I can offset by 1 for the query loop after the hero area?
Thanks,
NancyFebruary 12, 2023 at 9:58 pm #2530958Fernando Customer Support
You can set an offset through code.
Try adding this PHP:
function wpsites_exclude_latest_post( $query ) { if ( ( $query->is_home() || is_archive() ) && $query->is_main_query() ) { $query->set( 'offset', '1' ); } } add_action( 'pre_get_posts', 'wpsites_exclude_latest_post', 1 );Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
February 13, 2023 at 9:35 am #2531805Nancy
Fantastic – works great! Best of both worlds. Thank you Fernando!
February 13, 2023 at 9:57 am #2531835Nancy
Well darn, I spoke to soon – it seems to repeat the query loop and doesn’t update going from page 2 on. I’ll try to convince the client to live with the extra stuff in the URL.
February 13, 2023 at 5:05 pm #2532232Fernando Customer Support
That’s odd. That code should just offset the query by 1.
The
?query-stringURL is the only method we can reliably allow pagination on query loops in static pages.The alternative would be to use a Block Element – Content Template instead. Using the code I provided to offset the query should work in this instance as well. Reference: https://docs.generatepress.com/article/block-element-content-template/
-
AuthorPosts
- You must be logged in to reply to this topic.