WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List of Custom Taxonomies with Descriptions (4 posts)

  1. the.green.timtam
    Member
    Posted 2 years ago #

    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.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    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;
    }
    ?>
  3. the.green.timtam
    Member
    Posted 2 years ago #

    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;
    }
    ?>
  4. vtxyzzy
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.