- This topic has 5 replies, 2 voices, and was last updated 3 years, 12 months ago by
Elvin.
-
AuthorPosts
-
August 25, 2021 at 12:58 pm #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.August 25, 2021 at 7:48 pm #1908599Elvin
StaffCustomer SupportHi 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-columnsAs 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/
August 26, 2021 at 1:15 am #1908777Hung
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 🙂
August 26, 2021 at 1:45 am #1908805Elvin
StaffCustomer SupportAh 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.August 26, 2021 at 2:00 am #1908819Hung
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 🙂
August 26, 2021 at 7:24 pm #1909741Elvin
StaffCustomer SupportWith 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.
-
AuthorPosts
- You must be logged in to reply to this topic.