Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 119348

berteh on "[Plugin: Ultimate CMS] How to show taxonomy with a post"

$
0
0

and if you want to stick to "standard" wordpress code

you can add the following to your content.php file (or other from Template Hierarchy) for a "detailed" list of all applied custom taxonomies terms:

<ul class="entry-taxonomies">
  <?php // taxonomies
  $id = get_the_ID();
  foreach ( get_object_taxonomies( get_post_type($id) ) as $taxonomy ) {
  	$terms_list = get_the_term_list( $id, $taxonomy, '<ul class="tax-terms"><li>', '<span class="tax-sep">'.__( ', ', 'twentytwelve' ).'</span></li><li>','</li></ul>' );
	if ( $terms_list ) {?>
  	<li><span class="tax-taxonomy"><?php echo $taxonomy; ?></span><?php echo $terms_list; ?></li><?php
	}
  }?>
</ul>

or, if you want a a shorter list of all applied terms to replace the current list of categories in the post "metadata", then edit your functions.php file to add the following function (change its name with the name of your template!):

if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
/**
 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
 * @since Twenty Twelve 1.0
 */
function twentytwelve_entry_meta() {	

	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );

    // taxonomies (replace category)
	$id = get_the_ID();
	  $taxonomy_terms_list = "";
	  foreach ( get_object_taxonomies( get_post_type($id) ) as $taxonomy ) {	  $terms_list = get_the_term_list( $id, $taxonomy, '', __( ', ', 'twentytwelve' ) );
      if ( $taxonomy_terms_list && $terms_list )
	    $taxonomy_terms_list .= __( ', ', 'twentytwelve' ).$terms_list;
	  else
		$taxonomy_terms_list .= $terms_list;
	}

	$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
		esc_url( get_permalink() ),
		esc_attr( get_the_time() ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() )
	);

	$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
		get_the_author()
	);

	// Translators: 1 is taxonmies terms, 2 is tag, 3 is the date and 4 is the author's name.
	if ( $tag_list ) {
		$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
	} elseif ( $taxonomy_terms_list ) {
		$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
	} else {
		$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
	}

    printf(
		$utility_text,
		$taxonomy_terms_list,
	  	$tag_list,
		$date,
		$author
	);
}
endif;

Viewing all articles
Browse latest Browse all 119348

Trending Articles