Site logo

[Support request] Category Archive pages – Adding a query loop before category post list

Home Forums Support [Support request] Category Archive pages – Adding a query loop before category post list

Home Forums Support Category Archive pages – Adding a query loop before category post list

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2546825
    Paul

    Hi There,

    Could you help me with the following.

    I’d like to add a I’d 3 ‘featured’ posts before the archive of all posts in category archive page. Could you give me any pointers on how I could do that (example page in private info)?

    cheers

    #2547351
    David
    Staff
    Customer Support

    Hi there,

    the featured posts .. are they specific to each category ?

    #2547389
    Paul

    Hi David,

    Yes they would featured posts from the same category so ideally would like to filter those out posts from the full listings for the archive below, if that makes sense.

    So would be:

    CATS CATEGORY
    
    Cats Featured Post 1 | Cats Featured Post 2 | Cats Featured Post 3
    ____________________________________________________________________________________
    
    List of other Posts in Category (filtered to not display 3 featured posts above)
    #2547926
    Ying
    Staff
    Customer Support

    Hi Paul,

    Yes, you can use a block element – loop template, and assign it to the category archive.

    You will be adding 2 GB query loop blocks.

    The 1st query loop block is to have 3 featured posts, you can manually select the 3 posts.
    The 2nd query loop block is to have the rest posts, you can exclude the 3 posts.

    #2548400
    Paul

    Great, thank you Ying – I’ll try that.

    #2549062
    Ying
    Staff
    Customer Support

    No problem 🙂

    #2549301
    Paul

    Hi Ying,

    I gave that a try (I only added the first query loop block so far) – See link in private info.

    Although I ran into an issue – what if we want the ‘Featured posts’ query loop block container to only show on the first page of the category archive (currently shows on all pages)?

    Cheers

    #2549813
    David
    Staff
    Customer Support

    Add this snippet to your site:

    function db_hide_block_on_paged( $block_content, $block ) {
        if ( is_paged() && ! empty( $block['attrs']['className'] ) && 'hide-on-paged' === $block['attrs']['className'] ) {
            $block_content = '';
        } 
        return $block_content;
    }
     
    add_filter( 'render_block', 'db_hide_block_on_paged', 10, 2 );

    Then any Block you want to remove on paged instances eg. the parent Container holding your featured post loop, give it an Advanced > Additional CSS Class of: hide-on-paged

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