I am trying to do something like this. Instead of returning a list of all the categories within a custom taxonomy, I only want to return the first one. I have a portfolio page with ‘media’ as my custom taxonomy. I want to show the name of each category inside ‘media’ (identity, print, web) as a link to a category archive. Underneath the link will be thumbnails of the posts in that category.
When I use the get_term_link inside the loop, it returns the link each time it shows a post. If I use it in its own seperate loop it returns the link like I want, but it returns it multiple times depending on the number of posts.
<?php
$post_type = 'Portfolio';
$tax = 'media';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$divName = $tax_term->name ;?>
<div class="<?php echo $divName; ?>">
<?php echo $tax_term->name. ' Projects ' ;
This is what I’m using now to display the category name a single time. Is it possible to attach the link to this? Can get_term_link be used outside the loop, or modified to return only the first result?