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.

Carousel Using Post Loop To Return Categories, Tags, and Custom Taxonomy

  • Context:
    Standard WP Posts utilizing the Categories, Tags, and a custom taxonomy called ‘Message Topics’ (created in ACF) in the following way:
    Categories = Conference Year – using much like the name of a podcast. Think 3-5 different podcasts
    Tags = Speaker name – much like a podcast host
    Message Topics – topic or topics assigned to each message for 1) topic search and 2) filtered display on the main search page

    The layout I’m trying to achieve would be similar to a streaming service or podcast player

    Currently I’m trying to figure out 2 things:
    1. how to use the post loop to return to not just return a carousel of posts but a carousel of tags (speaker names) and custom taxonomy (Message Topics). I can get it to return the posts, but not the taxonomies themselves. Perhaps it’s not made to do that. (One taxonomy per carousel block)
    2. Size each container in the post loop to be perfectly square (1:1 ratio). I’ve tried setting min and max width values in pixels but they aren’t exactly coming out right.

  • Hi there,

    1. Query loop can only show posts or custom posts, it can not loop through taxonomy terms. You can try WP’s tag cloud block or category list block, for custom taxonomy, you will need to write custom PHP code to show them.

    2. The grid container width is set to 150px, however, it includes 20px padding-left (horizontal gap), so your container height should be 150px – 20px = 130px to make a perfect square.

  • Thank you. I wondered if that was the case.

    By chance would it be possible to hook into the query loop and do that with some custom php using the classes feature on the grid block within the query loop?

  • Yes, you can use the render_block filter to output any content you want.

    Here’s an example for render GB’s headline block:

    add_filter( 'render_block_generateblocks/headline', function( $block_content, $block ) {
        if ( 
          !is_admin() && 
          ! empty( $block['attrs']['className'] ) && 
          strpos( $block['attrs']['className'], 'my-custom-class' ) !== false 
        ) {
          
          // do your custom function here
          // generate $block_content
        }
      
        return $block_content;
     }, 10, 2 );
  • Thank you. I’ll try it out.

    Is that a better approach to the query loop than what David suggested here: https://generate.support/topic/query-loop-logic-and-sorting/#post-110187

  • It’s a different topic, that is to alter the posts of the query loop, not adding content to the query loop.

  • As I’m working on it, and for clarity’s sake, I’m targeting ‘generateblocks/query-loop’ but placing the class on the Grid block that’s within the Query Loop, correct?

  • Hi there,

    thats correct.

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