• Resolved Tim

    (@thegreentimtam)


    I’m working on a site for a band, and I want to know if it’s possible to create a list of Custom Taxonomies and their descriptions in a similar way to the loop.

    Basically, what I’ve done is made a Custom Post Type (called Music) and a Taxonomy (called Albums) for this post type. What I thought was that it would be possible to create a page that could list the the Albums in a similar way to the loop, using the description as a URL for an image.

    So, for example, I could create an Album called “Heartless” and then use the description as a URL to the Album artwork, and then use PHP to generate the code:

    <a href="heartless-archive"><p><img src="heartless-decription" /></p>
    <p>Heartless</p></a>

    Is this possible, or is there a better way of doing it?

    I hope you understand. It’s kind of complex.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think this will do what you want:

    <?php
    $siteurl = home_url('/');
    $imgurl = $siteurl . 'wp-content/uploads/test-images';  // Folder where images are located
    $tax = 'madeof';  // slug of taxonomy to list
    
    $terms = get_terms($tax);
    foreach ($terms as $term) {
       $slug = $term->slug;
       $description = $term->description;
       $link = "<a href='$siteurl?$tax=$slug' ><p><img src='$imgurl/$description' alt='$description' /> $term->name </p></a>";
       // echo '<p>' . htmlspecialchars($link) . '</p>';
       echo $link;
    }
    ?>
    Thread Starter Tim

    (@thegreentimtam)

    Thanks!! It worked!!

    I’m using fancy links (or whatever they’re called) so I edited the code to the following, in case anyone wants it…

    <?php
    $siteurl = home_url('/');
    $imgurl = $siteurl . 'album-artwork';  // Folder where images are located
    $tax = 'band_albums';  // slug of taxonomy to list
    
    $terms = get_terms($tax);
    foreach ($terms as $term) {
       $slug = $term->slug;
       $description = $term->description;
       $link = "<a href='$siteurl/$tax/$slug' ><p><img src='$imgurl/$description' height='220' width='220' alt='$description' /> </br>$term->name </p></a>";
       // echo '<p>' . htmlspecialchars($link) . '</p>';
       echo $link;
    }
    ?>

    Please use the dropdown on the right to mark this topic ‘Resolved’. That way, others can see that there is a solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘List of Custom Taxonomies with Descriptions’ is closed to new replies.