[Support request] show custom taxonomy in template

Home Forums Support [Support request] show custom taxonomy in template

Home Forums Support show custom taxonomy in template

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1908432
    Hung

    So, I have a custom taxonomy. Would like to show in frontend, in 2 or 3 columns. Is there anyway to use Grid in GenerateBlocks in a template? Or what is the best practice for showing dynamic data in columns (mobile friendly) in a template?

    Please suggest.
    Thanks.

    #1908599
    Elvin
    Staff
    Customer Support

    Hi there,

    You can try playing around with these codes depending if it’s associated with a custom post type as well:

    https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
    https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns

    As for the conditions, you can use is_tax() to specify the taxonomy
    https://developer.wordpress.org/reference/functions/is_tax/

    Here’s how to add PHP snippets – https://docs.generatepress.com/article/adding-php/

    #1908777
    Hung

    Hi Elvin.

    Thanks for answering. I might not be very clear in my question.

    I don’t want to show posts in that custom taxonomy. In that custom taxonomy, I have created many sub-taxonomies. I already get list of sub-taxonomies by get_terms() function. And I want to show those sub-taxonomies to 2-3 columns.

    So, I created a page template, using get_terms() function to get all the terms. I can show them like this

    foreach ( $terms as $term )
    			{
    				$term_info = $term->name." (".$term->count.")";
    				printf( '<div class="tax_preview"><h2><a href="%s">%s</a></h2></div>',
    						get_term_link( $term ),
    						$term_info 
    					);
    			}

    Then wondering if I can split to multiple columns automatically somehow, or will I need to write 2-3 div manually in the template? And adding CSS for them to be mobile friendly?

    Hope my question to be clearer now 🙂

    #1908805
    Elvin
    Staff
    Customer Support

    Ah my bad. You mean you want show the taxonomy term on your template.

    In general, you can always pull in any dynamic value with GB’s headline block in a Block element.

    But the column was a bit confusing. Are you trying to put 1 taxonomy term for each column?

    If yes, I don’t think that’s doable with the means within Gutenberg as we don’t have some sort of “Repeater” query for blocks like some page builders do. (example: Oxygen Builder’s Repeater widget)

    You’ll have to manually do your columns within the function that renders the taxonomy terms.

    So you basically wrap output iterations of your foreach with its own <div> column and then style it accordingly.

    #1908819
    Hung

    With Gutenberg, I found this https://ultp.wpxpo.com/taxonomy/ I would like to have something like style 8 or 11. Just don’t want to use an extra plugin with many functions, while I only need one. That’s why wanted to check if it’s doable with GP and GB 🙂

    #1909741
    Elvin
    Staff
    Customer Support

    With Gutenberg, I found this https://ultp.wpxpo.com/taxonomy/ I would like to have something like style 8 or 11. Just don’t want to use an extra plugin with many functions, while I only need one. That’s why wanted to check if it’s doable with GP and GB 🙂

    You won’t actually need a plugin for this. TBH I think your foreach PHP snippet is enough, just modify it a bit to have a wrapper for all the terms.

    And then set this wrapper to display: grid; or display: flex; and then set the columns to 50% and add the necessary CSS for similar animations. 😀

    But yeah, to answer the question directly, GB + GP can’t do that directly yet.

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