Open pascalinger opened 4 years ago
Anyone have a quick snippet to use to output all terms of a taxonomy within a repeater without the link?
@pascalinger
This is probably a bit late, but the following code in the PHP & HTML tab of a Code Block element should do the trick:
<?php
$post_id = get_the_ID();
$cats = wp_get_post_categories($post_id);
$cat_names = array();
foreach($cats as $cat){
$individual_cat = get_category( $cat );
$cat_names[] = ($individual_cat->name);
}
$cat_list = implode(", ", $cat_names);
?>
<div><?php echo $cat_list;?></div>
Yeh this is needed really. The need for more control over the dynamic data is essential
i'm trying different ways to kill the links but none is working. the code @KittenCodes wrote seems to have no effects. and i mean, blank output.
this is a feature i'd really like to have, easily accessible.
Unfortunately, there still doesn't seem to be a solution for this in Oxygen. Even in Toolset it has been possible to output taxonomies without a link for months without any problems.
I'm currently building a card (div) in an Oxygen repeater that contains, among other things, a dynamic taxonomy. If I now want to link the whole card dynamically, it shatters the whole CSS of the map.
<?php $post_id = get_the_ID(); $cats = wp_get_post_categories($post_id); $cat_names = array(); foreach($cats as $cat){ $individual_cat = get_category( $cat ); $cat_names[] = ($individual_cat->name); } $cat_list = implode(", ", $cat_names); ?> <div><?php echo $cat_list;?></div>
Above code is not working unfortunately... is there any other workaround this? Thank you
@wacaszafar
Please use the following code in a Code Block. You may need to set the width of the Code Block to 100%. You will also need to replace 'category' on line 3 with the slug of the taxonomy that you want to use:
<?php
$post_id = get_the_ID();
$taxonomy= 'category';
$terms = get_the_terms($post_id, $taxonomy);
if ($terms) {
$term_arr = array();
foreach ($terms as $term) {
$name = $term->name;
$term_arr[] = $name;
}
$my_terms = implode (", ", $term_arr);
}
?>
<div class=""><?php echo $my_terms; ?></div>
@wacaszafar
Please use the following code in a Code Block. You may need to set the width of the Code Block to 100%. You will also need to replace 'category' on line 3 with the slug of the taxonomy that you want to use:
<?php $post_id = get_the_ID(); $taxonomy= 'category'; $terms = get_the_terms($post_id, $taxonomy); if ($terms) { $term_arr = array(); foreach ($terms as $term) { $name = $term->name; $term_arr[] = $name; } $my_terms = implode (", ", $term_arr); } ?> <div class=""><?php echo $my_terms; ?></div>
How do I modify the code to work with dynamic taxonomies?
I have a suitable solution: many thanks at this point to Davide Del Gatto, who gave me the decisive hint.
In the new Oxygen version 3.8 (currently only available as RC version; but the final version should follow soon) you can select the following red marked section to insert (dynamic) taxonomies WITHOUT link.
oh yes thanks sweet baby alejandro
Il giorno 8 giu 2021, alle ore 23:48, survivestyle5plus @.***> ha scritto:
I have a suitable solution: many thanks at this point to Davide Del Gatto, who gave me the decisive hint.
In the new Oxygen version 3.8 (currently only available as RC version; but the final version should follow soon) you can select the following red marked section to insert (dynamic) taxonomies WITHOUT link.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I have a suitable solution: many thanks at this point to Davide Del Gatto, who gave me the decisive hint.
In the new Oxygen version 3.8 (currently only available as RC version; but the final version should follow soon) you can select the following red marked section to insert (dynamic) taxonomies WITHOUT link.
Sadly, for me, this outputs the term slug, not the name of the term. Desperately trying to get Oxy to output the name of the taxonomy term without the url/link wraparound, not the term slug.
Incidentally, my current workaround is to add the taxonomy as a Relation field in the Pod it belongs to, giving me a dropdown when creating new items in that CPT. I can then get the name (without link!) by using .name on that field, e.g.:
[oxygen data='meta' key='relational-field-in-pod-that-holds-the-tax-name.name']
EDIT — Just for kicks, I tried the following, with no success:
[oxygen data='post_terms' taxonomy='tax-name.name']
Guessing the .name thing only works for arrays.
I have this need today. I'm showing CPT posts in a repeater and want to output some tags but they should not be links as I won't be having archive pages for tags on this site.
The above mentioned screenshot under "Advanced" only shows the slugs so it's not the correct spelling for the tag name.
Incidentally, I tried to see what other option are available for the [oxygen....
shortcode but couldn't find anything. I thought maybe there could be arguments for how it outputs?
Would be very helpful to have a little more control over the output of some of these dynamic bits.
@guyinpv Please see: https://github.com/soflyy/oxygen-bugs-and-features/issues/1684#issuecomment-855203488
Good work around but still need implementation into the oxygen UI for easier use.
@guyinpv Please see: #1684 (comment)
That's not really my situation, I'm not on a post, I'm on an archive page. The repeater is showing each CPT post and inside the repeater I'm listing the tags. Would this code block be needed inside the repeater or on the outer archive template?
I'm not really sure on the inner workings of a repeater but I assume that if I put a code block inside the repeater div, the code is working in the context of "the loop"? I just don't know.
My workaround was to set pointer-events to none and then style up the links, but of course the page source still has a link to tag URLs that don't work.
@guyinpv You can use below code snippet in a code block.
<?php echo strip_tags( get_the_term_list( get_the_ID(), 'category', '', ', ' ) ) ?>
@guyinpv You can use below code snippet in a code block.
<?php echo strip_tags( get_the_term_list( get_the_ID(), 'category', '', ', ' ) ) ?>
This is the first I've seen this as an option. It works!
I still needed to style each individual tag so I had to allow for a span tag. Mine is this:
echo strip_tags(get_the_term_list(get_the_ID(), 'my_taxonomy', '<span>', '</span><span>', '</span>'), ['span']);
I guess this confirms if I put code inside a repeater, it's in the context of the loop and should be able to use normal inner loop functions.
Thanks!
@wacaszafar
Please use the following code in a Code Block. You may need to set the width of the Code Block to 100%. You will also need to replace 'category' on line 3 with the slug of the taxonomy that you want to use:
<?php $post_id = get_the_ID(); $taxonomy= 'category'; $terms = get_the_terms($post_id, $taxonomy); if ($terms) { $term_arr = array(); foreach ($terms as $term) { $name = $term->name; $term_arr[] = $name; } $my_terms = implode (", ", $term_arr); } ?> <div class=""><?php echo $my_terms; ?></div>
I've been looking for this for a long time now. It works!! Thank you!
+1 though for a UI solution for this.
@guyinpv You can use below code snippet in a code block.
<?php echo strip_tags( get_the_term_list( get_the_ID(), 'category', '', ', ' ) ) ?>
This is also what I needed - thank you!
Can that code be adapted to include ordering by term title?
I need this too. I can't believe it isn't available - seems like a major oversight.
Not sure what might be the real problem but you can easily disable with css. Just add a class somewhere on a main div or link itself. Then use "pointer-events: none" on that a tag.
E.g:
.your-class a { pointer-events: none; }
I'd also like this feature
Not sure what might be the real problem but you can easily disable with css. Just add a class somewhere on a main div or link itself. Then use "pointer-events: none" on that a tag.
E.g:
.your-class a { pointer-events: none; }
This is a workaround, not a real solution. We wouldn't want an anchor tag in our DOM if we are not going to use it.
I have a suitable solution: many thanks at this point to Davide Del Gatto, who gave me the decisive hint.
In the new Oxygen version 3.8 (currently only available as RC version; but the final version should follow soon) you can select the following red marked section to insert (dynamic) taxonomies WITHOUT link.
Thank you! This is exactly what I needed. Maybe it could be made more clear in the UI which one is with/without a link. Also it would be nice to adjust the link.
@KittenCodes Isn't this already available now, as mentioned above?
@KittenCodes @Kpudlo, The option Advanced > Taxonomy Terms is NOT the solution. For instance, post tags are shown as SLUG, not as NAME. Just tested with Oxygen 4.3
I still need this Code Block to show the tag names:
<?php echo strip_tags( get_the_term_list( get_the_ID(), 'post_tag', '', ', ' ) ) ?>
Hey @maltmann-muc,
Yes, you are correct; my apologies. I've reopened this feature request.
You can also use the following code in a Code Block element:
<?php
$separator = ', '; //change this to whatever you want the separator to be
$taxonomy = 'category'; //change this to the slug of your taxonomy
$term_obj_list = get_the_terms( get_the_ID(), $taxonomy );
if($term_obj_list) {
$terms_string = join($separator, wp_list_pluck($term_obj_list, 'name'));
if($terms_string) {
echo $terms_string;
}
}
?>
Thank you, @Kpudlo, for re-opening this ticket. I appreciate. You're suggesting to replace the one-liner code with a 10-liner? ;-)
The code works perfectly, but what if I want to input 2 taxonomy on the same page? I try to modify it for two tax, but it doesn't work.
Also, I am curious about this code for tag taxonomy. I did tried but failed too.
@Kpudlo regarding your code from Jan 23. For me, it does not seem to work in a repeater. I am using a custom taxonomy on a custom post type (generated by Meta Box), not sure if that is the problem. Using Dynamic Data for Taxonomy and Taxonomy Terms does for these custom objects as expected, so I doubt that it has much to do with Meta Box. Any advice on this?
@Kpudlo regarding your code from Jan 23. For me, it does not seem to work in a repeater. I am using a custom taxonomy on a custom post type (generated by Meta Box), not sure if that is the problem. Using Dynamic Data for Taxonomy and Taxonomy Terms does for these custom objects as expected, so I doubt that it has much to do with Meta Box. Any advice on this?
Disregard... It did work
Describe the feature you'd like to see included in Oxygen. A clear, detailed description of the feature you're requesting. Add an option to output taxnonmies without a link.