Support » Plugin: Ultimate CMS » How to show taxonomy with a post

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author XYDAC

    (@deepakseth)

    There are two ways to do that
    – you need to change the theme files and add some code to display what you want
    – or may be you could add a shortcode used for displaying the taxonomy below each post.

    Regards,
    -Xydac

    pietsj

    (@pietsj)

    I understand how to print things before the post itself (see below), but i don’t know the comment to extract the terms for the post for a given XYDAC taxonomy. Please help.

    I tried something like $club_list in the following code in place of $categories_list and then definiting $club_list = get_terms( $instance[‘taxonomy’]);
    but replacing ‘taxonomy’ with ‘clubs’ as that is the name of one of the XYDAC taxonomy. That failed.

    – – – – – – – – – – – – –

    <?php
    $categories_list = get_the_category_list( __( ‘, ‘, ‘sundance’ ) );
    if ( $categories_list && sundance_categorized_blog() ) :
    ?>
    <span class=”cat-links”>
    <?php
    printf( __( ‘Speech purposes %1$s’, ‘sundance’ ), $categories_list );
    ?>
    </span>

    <?php endif; ?>

    Plugin Author XYDAC

    (@deepakseth)

    Well, I don’t think you need to write this much of code even, i suppose you can print out the taxonomies using the shortcode [xy_club]

    Then may be you can add the following code to you theme file
    do_shortcode('[xy_club]');
    wherever you want to display your taxonomies.

    Please let me know if this fixes your issue?

    Regards,
    -Xydac

    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  + custom taxonomies terms, tags, permalink, author, and date.
     * @since Twenty Twelve 1.0
     */
    function twentytwelve_entry_meta() {	
    
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    
        // taxonomies (categories and other terms)
    	$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 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to show taxonomy with a post’ is closed to new replies.