Displaying Taxonomy terms with Shortcode in Custom Post
-
I have a custom post ‘downloads’ with two taxonomy ‘groups’ and ‘items’
I want the terms from ‘groups’ and ‘items’ to span out in post linking to their archive pages using shortcodes.e.g
Groups: Electronic
Items: phone, GagetWhat i want is the same as the ‘category’ and ‘tags’ on archive3d.net
I’ve been able to get the following Codes
/*******display tag in post********/ function tags_in_post($atts) { // [tags] outputs post's tags in a span global $post; $tags = '<span class="post-tags">'; ob_start(); the_tags( '<span class="post-tags">', ', ', '</span>' ); $tags = ob_get_contents(); ob_end_clean(); return $tags; } add_shortcode ('tags', 'tags_in_post');
This code works fine and spans out the terms but it only works with default post_tags
/** * Example: [wp custom_taxonomy="taxonomy_slug"] */ // First we create a function function list_terms_custom_taxonomy( $atts ) { // Inside the function we extract custom taxonomy parameter of our shortcode extract( shortcode_atts( array( 'custom_taxonomy' => '', ), $atts ) ); // arguments for function wp_list_categories $args = array( taxonomy => $custom_taxonomy, title_li => '' ); // We wrap it in unordered list echo '<ul>'; echo wp_list_categories($args); echo '</ul>'; } // Add a shortcode that executes our function add_shortcode( 'ct_terms', 'list_terms_custom_taxonomy' ); //Allow Text widgets to execute shortcodes add_filter('widget_text', 'do_shortcode'); // shortcode to use [ct_terms custom_taxonomy=customtaxonomyname]
Code Two is almost perfect my problems with this are;
1. the list jumps to the top of the page. I want the terms in front of each taxonomy (where the shortcode is pasted).2. its a list, i want the terms spanned out in from of each other and separated by commas
I’ve tried many plugins, tried to mix these two codes but I’ve not been able to achieve much.
I’m very new to WordPress and Coding is quite new to me, I will be glad if somebody can spoon-feed me the code to achieve this. I’ve been stuck at this point for days.
Please Help!
- The topic ‘Displaying Taxonomy terms with Shortcode in Custom Post’ is closed to new replies.