- This topic has 15 replies, 3 voices, and was last updated 1 year, 11 months ago by David.
-
AuthorPosts
-
October 14, 2022 at 5:34 am #2373316Lewis
A huge part of my site is build on WPSP but as this is not being updated anymore, it’s advised that I move things to GenerateBlocks which I’m TRYING to do but I’m hitting a bit of a road block with archive pages.
How do I create an archive page template which can be rolled out to all category pages instantly without having to create a template for each category.
I want to pull in the archive title then use queryposts to pull in 3 featured posts followed by the usual loop which needs to be offset by 3. This was all set up in WPSP and assumed GenerateBlocks would offer the same functionality.
But when I select “Categories” then “Current post terms” it doesn’t pull in any posts. How do I select the current category here?
October 14, 2022 at 7:27 am #2373426DavidStaffCustomer SupportHi there,
quick question – how do you define the 3 featured posts ? is that using a taxonomy term or something ?
October 14, 2022 at 7:28 am #2373427LewisAh sorry, should have said. Yes, it is a taxonomy (tag) such as ‘featured’
October 14, 2022 at 7:47 am #2373449DavidStaffCustomer SupportOk, can i see what you currently have, so i can then propose some solutions ?
October 14, 2022 at 7:50 am #2373570LewisNot a lot! It wasn’t working so pulled what I had from the site as it was messing with the layout. I know, that doesn’t help!
I set up a query loop, set limit to 3 and then selected taxonomy, current post
But that doesn’t work for pulling in posts from the current taxonomy.That’s the main sticking point: Trying to find a way to use Query Loop to fetch posts from the current taxonomy.
October 14, 2022 at 7:57 am #2373607DavidStaffCustomer SupportI meant the WPSP version ? 🙂
October 16, 2022 at 11:43 pm #2375844LewisAh sorry, I’m no longer using WPSP as I was seeing a warning on the site that it was no longer being updated and that Generate Blocks offered everything that WPSP could do.
I didn’t want to run an unsupported plugin so moved everything over fine except category pages.
I just want some sort of featured block at the top of the category listings which pulls in posts with a given tag and displays on every category page.
There are 2 issues:
1. I cannot get the query loop to get posts for the current category. I have to select the category which would require me to set up 20+ individual blocks2 – If my blog is set to display archives in 3 columns in GeneratePress then columns don’t work in Generate Blocks. It forces everything into 3 columns.
Thanks for any help!
October 16, 2022 at 11:53 pm #2375847Fernando Customer SupportHi Lewis,
Thank you for clarifying. If you’re trying to use a Query Loop Block to layout your archive pages, this would be easily possible through a Block Element – Loop Template. Reference: https://docs.generatepress.com/article/block-element-loop-template/
If you set the Query loop to “Inherit Query from template” as stated in the article, the Queried posts should be that of the current archive page.
The Loop Template will be available on GP 3.2.0 with GP Premium 2.2.0. For now, you can download the release candidate versions here: https://generatepress.com/account/
October 17, 2022 at 12:00 am #2375853LewisYeah I have the Loop Template option but that doesn’t allow me to apply a tag filter? It will just pull in the latest posts from the archive.
October 17, 2022 at 12:06 am #2375858Fernando Customer SupportTags are a different archive page. If you visit a category archive page, you’ll see all posts of that category. If you visit a tag archive page, you’ll see all posts with that tag. To view this, in your admin dashboard, go to Posts > Tags, and view a specific tag category archive.
October 17, 2022 at 12:10 am #2375863LewisNo I get that. Sorry I’m not being clear.
I want to add a few featured posts at the top of a category page which are filtered by a tag (tag set as featured for example).
October 17, 2022 at 12:20 am #2375871Fernando Customer SupportI see.
To clarify, you have a Query Loop in a Loop Template, and in this Query Loop, you want the ones on top to be the ones tagged as “Featured”?
October 17, 2022 at 12:30 am #2375880LewisI don’t have anything at the moment! Ha.
But my plan is to have let’s say 3 featured posts followed by the usual loop. Those 3 featured posts would be from within the current category AND must have a specified tag.October 17, 2022 at 3:41 am #2376057DavidStaffCustomer SupportOk, so i think for this kind of requirement it would make sense to NOT use the Loop Template and Query Loop.
Instead, use the Block Element – Content Template x 2 instead.1. Create a Content Template for the design of the non-featured posts. And set the Display Rule > Location to:
Post Category Archive -> All Archives
2. Now create a second Content Template for the featured post design.
In the Elements sidebar see here:https://www.screencast.com/t/MzkSozjyKhl
You want to set the:
Apply to: Posts with Term
Taxonomy: post_tag
Term name: whatever your featured post tag is
Parent Element: Here you select the template you created in step 1Note this will remove the Display Rules from that element as it will inherit the parent elements rules.
When viewing the archive you should now see a mix of the two templates.
3. Now ( fingers crossed here ) we need to float the featured tag posts to the top. Which doing a little research can be done with this Snippet:
add_action( 'loop_start', function( $q ) { if( $q->is_main_query() && $q->is_category() ) usort( $q->posts, function( $a, $b ){ return -1 * has_tag( 'featured', $a ) + 1 * has_tag( 'featured', $b ); }); }, 10, 2 );
Note: the 2 instances of the tag term here:
has_tag( 'featured', $a ) + 1 * has_tag( 'featured', $b )
– those need to match your term.October 17, 2022 at 3:49 am #2376058LewisDavid, you hero! This will work perfectly.
-
AuthorPosts
- You must be logged in to reply to this topic.