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="http://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="http://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="http://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!