[Resolved] How to Create Custom Archive Pages Using GenerateBlocks?

Home Forums Support [Resolved] How to Create Custom Archive Pages Using GenerateBlocks?

Home Forums Support How to Create Custom Archive Pages Using GenerateBlocks?

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
  • #2373316

    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?

    Customer Support

    Hi there,

    quick question – how do you define the 3 featured posts ? is that using a taxonomy term or something ?


    Ah sorry, should have said. Yes, it is a taxonomy (tag) such as ‘featured’

    Customer Support

    Ok, can i see what you currently have, so i can then propose some solutions ?


    Not 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.

    Customer Support

    I meant the WPSP version ? 🙂


    Ah 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 blocks

    2 – 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!

    Customer Support

    Hi 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/


    Yeah 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.

    Customer Support

    Tags 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.


    No 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).

    Customer Support

    I 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”?


    I 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.

    Customer Support

    Ok, 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:


    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 1

    Note 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.


    David, you hero! This will work perfectly.

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