Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Editing query loop pattern template

  • so I am using same query loop pattern block template for these pages

    /blog/
    /blog-category-acrhieve/

    I do want /blog/ and /blog-category-archieve/ page to have same style. But how do I edit this pattern block so, /blog-category-archieve/ returns only articles from that category and not from all categories.

    I am using one of your pattern block and I am assuming that pattern is for /blog/ template, which is why it is returning articles from all categories ?

    Thank you.

  • Hi Huppap,

    You need to use a Block Element – Content Template or Loop Template for an Archive/Blog page. References:

    https://docs.generatepress.com/article/block-element-content-template/
    https://docs.generatepress.com/article/block-element-loop-template/

    In a Loop Template, you will be able to add the “Pattern” you used.
    Are you planning to show just 3 posts? Moreover, what will be the overall design of the archive/blog pages if there will be more than 3 posts?

  • I actually used your loop pattern block, so I am assuming that it will update with more added as I publish them.

    It looks like this pattern is limited to 4 posts only.

    What I am trying to achieve is use this pattern for the top part and then show rest of the posts underneath it.

    Is there a way for me to make /blog/ and /blog-category-archive/ page with generate blocks?

    I seriously thought your pattern block was going to take care of that.

  • if you look at the /blog/ template, I was able to add another query loop element and offset the posts by 4 (in order to cover for 4 already shown on the top). Right now I set the offset to 2 since I have only 4 posts in total so far.

    Will that do the job for /blog/ page?

    if yes, how can I achieve same design for /blog-category/ page but which shows posts only from that specific category.

    Thank you.

  • little update, I think I was able to update the query loop to show posts from specific category as well.

    please check /blog/ vs /blog/category/how-to-guides/

    Only thing I am missing right now is how the pagination will work in this setup.

    Can you please help me with that?

    Thank you.

  • Hi there,

    for the Category pages, in its Block Element Loop Template, add a Query Loop Block. DO NOT set any parameters, just select the Inherit Query from Template option, and set the Display Rules Location to:

    Post Category Archives -> All Categories

    or All Archives if you want it to apply to to other tax archives.

    For Pagination, select the Query Loop block and in its Toolbar there is an option add Pagination.

  • thanks dave, your suggestions are always awesome and very helpful.

    I was also able to inherit query from the template in case of /blog/ page as it was set as latest post template in homepage settings.

    This solved my issue for now, but I had to use the different design, a simple design.

    The prebuilt pattern block template that I was using before had 2 queries in it. Would be have been cool if that whole pattern block was made with just one query.

    Plus in case of /blog/ if I add pagination to bottom query element next page still had the top section visible. This design seems like will require some work from my end to implement.

  • Creating a single query that has various designs is possible but complicated.

    For example – the Volume site uses the the homepage to show the latest posts and 2 x Block Element Content Templates to design the post layout:

    https://gpsites.co/volume/

    That uses the single theme loop but with a different template for the first post.

    The alternative with 2 x Query Loop blocks is to do:

    1. create a Loop Template to replace the blog page loop.
    1.1 don’t set the inherit query option just add a Offset of X Pages
    1.2 add your pagination block

    2. create a block element hook to come before the loop.
    2.1 add query loop with your other design and set the pages to show X
    2.2 make a note of this elements ID

    3. Add this PHP Snippet to your site to remove the #2 element when viewing paged instances:

    add_filter( 'generate_element_display', function( $display ) {
      if ( 100 === $element_id && is_paged() ) {
         $display = false;
      }
    
      return $display;
    } );

    Change the 100 to match your element ID.

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