• Resolved Star Verte LLC

    (@starverte)


    To display the list of tags for my posts, I am using <?php echo get_the_term_list( $post->ID, 'option', 'Choice of: ', ' or ', '<br />' ); ?>

    However, I would really like the choices to be separated by a comma, except the last one is separated with an “or”

    Example use: A post is titled “iPod” and is available in different colors: “Red” “Orange” “Yellow” “Green” “Blue” “Violet”

    How do I display at the bottom of the post:

    Choice of: Red, Orange, Yellow, Green, Blue, or Violet

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • try:

    <?php echo strrev(preg_replace('/ ,/',' ro ,', strrev(get_the_term_list( $post->ID, 'option', 'Choice of: ', ', ', '<br />' )),1)); ?>

    https://php.net/manual/en/function.preg-replace.php
    https://php.net/manual/en/function.strrev.php

    Thread Starter Star Verte LLC

    (@starverte)

    Sweet. That worked. Thank you so much.

    I ended up needing to use get_the_terms because I didn’t want the hyperlinks for the list, but you definitely led me in the right direction. I ended up with:

    <?php
    		$terms = get_the_terms( $post->ID, 'option' );
    
    		if ( $terms && ! is_wp_error( $terms ) ) : 
    
    			$option_links = array();
    
    			foreach ( $terms as $term ) {
    				$option_links[] = $term->name;
    			}
    
    			$choice_of = join( ", ", $option_links );
    
    		?>
    
    		<p class="choices">
    			Choice of: <?php echo strrev(preg_replace('/ ,/',' ro ,', strrev($choice_of),1)); ?>
    		</p>
    
    		<?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I customize the category/custom taxonomy list?’ is closed to new replies.