• Resolved Dan

    (@danrip)


    Giving myself grey hairs over this one. Much appreciated if anyone can help out.

    I have a custom post type – Locations. It has a custom taxonomy – Triptypes. The taxonomy has 8 terms in it. The 8 terms are assigned to their relevant posts.

    What query / content do I need to put in the ‘taxonomy-triptypes.php’ file for it to render just those 8 terms on a page (NOT the posts assigned to them)?

    The posts in the terms display fine with ‘taxonomy-triptypes-term-name.php – but I can’t seem to hit on a solution to display the terms themselves (and I’ve tried more than a few…)

    What am I missing?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @dan,

    Have you tried using get_terms() function as following.

    $terms = get_terms("triptypes");
     $count = count($terms);
     if ( $count > 0 ){
         echo "<ul>";
         foreach ( $terms as $term ) {
           echo "<li>" . $term->name . "</li>";
    
         }
         echo "</ul>";
     }

    Kind Regards,

    Thread Starter Dan

    (@danrip)

    Ahh, thank you WPMU DEV!! You rock!

    Actually, I had used get_terms(), but I can see now that I’d dropped the crucial ‘$term->name’ in my attempts to merge the query into the way the rest of the page is displayed, namely:

    $triptype_featured_images = wp_get_attachment_image_src( get_post_thumbnail_id( ), 'triptype-big-featured' );
    			echo '<article class="' . implode( ' ', get_post_class() ) . '" itemtype="https://schema.org/ItemList" itemscope="itemscope">';
    				echo '<h2 class="entry-title"><a href="'. get_permalink() .'" title="'. get_the_title() .'">'. get_the_title() .'</a></h2>';
    				echo '<a href="'. get_permalink() .'" title="'. get_the_title() .'" class="location-hover">';
    					the_excerpt();
    				echo '</a>';
    				echo '<img class="aligncenter" src="'. $triptype_featured_images[0] .'" alt="'. get_the_title() .'"></a>';
    			echo '</article>';
    }
    }
    }

    Can I ask – where would I drop $term->name into this? I’m using it from elsewhere in the site, and want to keep the layout uniform.

    Thank you

    Hi @dan,

    You are most welcome.

    You can add it anywhere in between opening and closing <article> tag.
    Example:

    $triptype_featured_images = wp_get_attachment_image_src( get_post_thumbnail_id( ), 'triptype-big-featured' );
    echo '<article class="' . implode( ' ', get_post_class() ) . '" itemtype="https://schema.org/ItemList" itemscope="itemscope">';
    	echo '<h2 class="entry-title"><a href="'. get_permalink() .'" title="'. get_the_title() .'">'. get_the_title() .'</a></h2>';
    	echo '<a href="'. get_permalink() .'" title="'. get_the_title() .'" class="location-hover">';
    		the_excerpt();
    	echo '</a>';
    	echo '<img class="aligncenter" src="'. $triptype_featured_images[0] .'" alt="'. get_the_title() .'"></a>';
    	$terms = get_terms("triptypes");
    	$count = count($terms);
    	if ( $count > 0 ){
    		echo "<ul>";
    		foreach ( $terms as $term ) {
    		echo "<li>" . $term->name . "</li>";
    
    		}
    		echo "</ul>";
    	}
    echo '</article>';

    Cheers.

    Thread Starter Dan

    (@danrip)

    FIXED! ?? *happy-dance* You definitely put me on the right road with that one – thank you so much!

    Once I’d found get_term_link too, it all started coming together. Here’s where I ended up:

    $terms = get_terms('triptypes');
    	foreach ($terms as $term) {
    	$term_link = get_term_link( $term, 'triptypes' );
    	if( is_wp_error( $term_link ) )
            continue;
    	$triptype_featured_images = wp_get_attachment_image_src( get_post_thumbnail_id( ), 'triptype-big-featured' );
    	echo '<article class="' . implode( ' ', get_post_class() ) . '"  itemtype="https://schema.org/ItemList" itemscope="itemscope">';
    	echo '<h2 class="entry-title"><a href="'. $term_link .'" title="'. $term->name .'">'. $term->name .'</a></h2>';
    	echo '<a href="'. $term_link .'" title="'. $term->name .'" class="location-hover">';
    		the_excerpt();
    	echo '</a>';
    	echo '<img class="aligncenter" src="'. $triptype_featured_images[0] .'" alt="'. get_the_title() .'"></a>';
    	echo '</article>';

    ..and once I’d flushed the permalinks, voila!

    Thanks again, your help was invaluable!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘taxonomy-$taxonomy.php template issues’ is closed to new replies.