adding inline CSS to a php function that displays categories
-
I’m using one of the 2 following examples to display what category(s) the post belongs to, in the post’s page.
Example 1
<?php $terms = get_the_terms( $post->ID , array( 'industry') ); // init counter $i = 1; foreach ( $terms as $term ) { $term_link = get_term_link( $term, array( 'industry') ); if( is_wp_error( $term_link ) ) continue; echo $term->name; // Add comma (except after the last theme) echo ($i < count($terms))? " / " : ""; // Increment counter $i++; }?>
Example 2
<?php $taxonomy = 'industry'; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // separator between links $separator = ', '; if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) { $term_ids = implode( ',' , $post_terms ); $terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids ); $terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator ); // display post categories echo $terms; } ?>
My problem is that I want to CSS the term displayed and replicate my theme CSS. Where do I change the code?
What’s the best code of those above, anyway?
Viewing 15 replies - 1 through 15 (of 15 total)
Viewing 15 replies - 1 through 15 (of 15 total)
- The topic ‘adding inline CSS to a php function that displays categories’ is closed to new replies.