Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #373743

    I’m using the enfold content element – table to display tabular data.
    I use the following code to show taxonomy.

    
    function list_terms_custom_taxonomy( $atts ) {
    	extract( shortcode_atts( array(
    		'custom_taxonomy' => '',
    	), $atts ) );
    $args = array( 'taxonomy' => $custom_taxonomy,
                   'title_li' => '',
    			   'show_count'=> 1,
    			   );
    echo '<ul class="tax_listing">'; 
    echo wp_list_categories($args);
    echo '</ul>';
    }
    add_shortcode( 'wp', 'list_terms_custom_taxonomy' );
    

    I use the shortcode [wp custom_taxonomy=slug] to display taxonomy in the post.

    Display of taxonomy works fine.
    Enfold Table works fine.
    So both works fine.

    The only problem I have is the taxonomy floating out of the table content. Regardless how I do it, it stubbornly appears on the top left corner of the post. I can’t have it sit within the table’s rows as intended. It doesn’t sit within the layout element too.

    Is that something wrong with my approach? I’ve google for two days but can’t seem to find a fix for this. If anyone reading this knows where did I go wrong, I truly appreciate if you can point me to the right direction.

    Thanks team!

    • This topic was modified 9 years, 12 months ago by senso.
    #373781

    Found a fix for this after more googling. Not sure if is the correct way but it does seem to solve my problem for now. Hopefully it will be helpful and time saving for theme owner who wants to do something similar.

    The problem here is the use of ‘echo‘. Use ‘return‘ is more appropriate and include ob_start() and ob_get_clean() buffering.

    The working code is as below

    function list_terms_custom_taxonomy( $atts ) {
    	extract( shortcode_atts( array(
    		'custom_taxonomy' => '',
    	), $atts ) );
    $args = array( 'taxonomy' => $custom_taxonomy,
                   'title_li' => '',
    	       'show_count'=> 1,
    			   );
    ob_start();
    $string1 = '<ul class="yourcssclass">';
    $string1 .= wp_list_categories($args);
    $string1 .= ob_get_clean();
    $string1 .= '</ul>';
    return $string1;
    }
    add_shortcode( 'wp', 'list_terms_custom_taxonomy' );

    Please note that I’m not a php coder so do it at your own risk.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Display taxonomy within table’ is closed to new replies.