• I’m linking directly to the only post using a custom taxonomy for reference. I use my WordPress for podcast hosting, and have created a custom taxonomy for hosts to easily see podcasts and episodes hosted by certain people.

    I’ve previously asked for help with post meta, so my entry meta is already present in my child theme. I just need to know 1) what functions are needed to display this new taxonomy along with the tags/categories on posts 2) how to structure these functions

    Cheers!
    Matt

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mattgcn

    (@mattgcn)

    Following up: I’ve gotten the proper text to display, but I’m unsure of the arguments needed to properly fetch the terms of a custom taxonomy, so right now it’s just grabbing the category again. How should this argument look for a custom taxonomy:

    /* translators: used between list items, there is a space after the comma */
    $terms_list = get_the_terms( ”, ‘, ‘ );

    Thread Starter mattgcn

    (@mattgcn)

    Hey I got it! It shows up correctly now. My concern now is trying to set up a stable structure so that when there are no hosts listed, the text does not show (like it would for tags). Here is my entire function, how is the best way to structure this?

    	/* translators: used between list items, there is a space after the comma */
    	$category_list = get_the_category_list( __( ', ', 'sela' ) );
    
    	/* translators: used between list items, there is a space after the comma */
    	$tag_list = get_the_tag_list( '', ', ' );
    	
    	/* translators: used between list items, there is a space after the comma */
    	$host_list = get_the_term_list( $post->ID, 'host', '', ', ', '');
    
    	if ( ! sela_categorized_blog() ) {
    		// This blog only has 1 category so we just need to worry about tags in the meta text
    		if ( '' != $tag_list && ! is_wp_error( $tag_list ) ) {
    			$meta_text = '<span class="tags-links">' . esc_html__( 'Tagged: %2$s', 'sela' ) . '</span>';
    		} else {
    			$meta_text = __( '<a href="%4$s" title="Permalink to %5$s" rel="bookmark">Permalink</a>.', 'sela' );
    		}
    
    	} else {
    		// But this blog has loads of categories so we should probably display them here
    		if ( '' != $tag_list && ! is_wp_error( $tag_list ) ) {
    			$meta_text = '<span class="cat-links">' . esc_html__( 'Posted in: %1$s', 'sela' ) . '</span><span class="sep"> | </span><span class="tags-links">' . esc_html__( 'Tagged: %2$s', 'sela' ) . '</span><span class="sep"> | </span><span class="hosts-links">' . esc_html__( 'Featuring: %3$s', 'sela');
    		} else {
    			$meta_text = '<span class="cat-links">' . esc_html__( 'Posted in: %1$s', 'sela' ) . '</span>';
    		}
    
    	} // end check for categories on this blog
    
    	// If $tag_list contains WP Error, empty before passing to printf()
    	if ( is_wp_error( $tag_list ) ) {
    		$tag_list = '';
    	}
    
    	printf(
    		$meta_text,
    		$category_list,
    		$tag_list,
    		$host_list,
    		esc_url( get_permalink() ),
    		the_title_attribute( 'echo=0' )
    	);
    }
    endif;

    In order for this to work you’d need to use a custom taxonomy widget rather than the categories one. The regular categories widget doesn’t seem to support custom taxonomies.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help displaying custom taxonomy information’ is closed to new replies.