- This topic has 8 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
February 24, 2023 at 1:54 pm #2545987
Steve
I’ve managed to display custom taxonomy items in the front end using the dynamic headline options.
Thanks to this post:
https://generatepress.com/forums/topic/custom-taxonomy-not-displaying-in-dynamic-data/
I’m pretty sure I can get them to display as a list using the the snippet Fernando posted in #2453884
Using custom CSS targeting the content of
li::before, I reckon I can probably get a checkmark to display before each taxonomy item like this:But…
How would I go about displaying a unique icon next to each taxonomy item like this please?
As well as GP/GB Pro I’m using CPT UI and ACF Pro.
February 25, 2023 at 3:20 am #2546329Steve
Here’s how I’m thinking I could approach this, please let me know if I’m barking up the wrong tree…
1. use ACF to add a custom text field (used to add a class name) to the custom taxonomy so that each term gets its own unique class. This field would be called ‘acf_term_class’. I know how to do that.
2. Use custom css to add a unique icon using the ::before pseudo-selector for each of those unique term class names. I know how to do that too.
3. Somehow inject the unique class names into Fernando’s code (I don’t know how to do that but ending up with something like the below)
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-tax-headline' ) !== false ) { $terms = get_field('custom-tax'); $output = '<ul>'; foreach( $terms as $term ){ $output = $output . '<li class="inject the term's unique classname here">' . '<a href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a></li>'; } $output = $output . '</ul'; return $output; } return $content; }, 10, 3);I’d also like to strip out the term links – not sure exactly the right way to do that either (I don’t know php) but perhaps this?:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-tax-headline' ) !== false ) { $terms = get_field('custom-tax'); $output = '<ul>'; foreach( $terms as $term ){ $output = $output . '<li class="inject the term's unique classname here">' . esc_html( $term->name ) . '</li>'; } $output = $output . '</ul'; return $output; } return $content; }, 10, 3);As ever, any help would be most appreciated. Thanks.
February 25, 2023 at 5:14 am #2546415David
StaffCustomer SupportHi there,
by default GenerateBlocks prints the
term-{slug}for as a CSS class for each term.Heres an example of the HTML taken from the Newsroom site in the GP Site Library::
<span class="post-term-item term-lifestyle"><a href="https://gpsites.co/newsroom/category/lifestyle/">Lifestyle</a></span>Which George the design took advantage of to change each terms color using custom CSS.
And you could do the same:
/* add generic styling for all pseudo items */ .post-term-item:before { margin-right: 10px; } /* add content to each term */ .post-term-item.term-lifestyle:before { /* do your content property thing */ }February 25, 2023 at 6:46 am #2546489Steve
Thanks David – so the class I was after is there already!
Was my edit to the php to remove the link around the term correct?
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-tax-headline' ) !== false ) { $terms = get_field('custom-tax'); $output = '<ul>'; foreach( $terms as $term ){ $output = $output . '<li>' . esc_html( $term->name ) . '</li>'; } $output = $output . '</ul'; return $output; } return $content; }, 10, 3);February 26, 2023 at 4:55 am #2547269David
StaffCustomer SupportYeah – it was top of the list when it can to building the list of terms feature, as otherwise you had to use href attributes in your CSS, which isn’t very pretty.
If you select the block showing the list of terms, in its dynamic data options, you can simply NOT set a link source, if you just want them as labels.
February 26, 2023 at 7:25 pm #2548017Steve
Sorry, I realise I made an error when referencing the other post with the add_filter example as that was talking about ACF taxonomy fields, not custom taxonomies as I thought.
What I am trying to achieve here is to format the list of terms in the front end as a proper unordered list, so the list is wrapped in
<ul>tags and each term is wrapped in an<li>tag.On a similar note, is it possible to use the Headline block to output the data from an ACF checkboxes field? I’ve not had any luck with that so far. I saw a post from April 22 saying it was on the list of things to do but wondered if that had been implemented yet in more recent versions of GenerateBlocks.
I can use the acf shortcode to display the list of active checkbox terms but it just comes through as a comma separated list, and again I’d like each to have its own class and ideally be formatted as a proper list.
February 27, 2023 at 5:18 am #2548464David
StaffCustomer SupportIf you need to loop through repeater fields or checkboxes then you would need to use an ACF Shortcode for that now.
GB Pro will handle that in a future updateFebruary 27, 2023 at 9:14 am #2548883Steve
OK thanks David, I’ll look into a Shortcode for the checkboxes.
Regarding the Taxonomy List of Terms that GB does currently support though, how do I display that as a proper unordered list in the front end (with
ulandlitags), rather that just a comma separated list please?February 27, 2023 at 9:38 am #2548937David
StaffCustomer SupportThere is no support for
UL/LItags for headlines or buttons at this time.
If you have GB Pro then you can use the blocks Advanced > Attributes to add arole=listattribute to the container, androle=listitemto the headlines. Those will then be treated as if they were a list. -
AuthorPosts
- You must be logged in to reply to this topic.

