2

I am trying to use the Category Images Plugin to show images with my Custom Taxonomy (Region) categories/terms. Here is the code I have so far in a page-example.php that lists all the categories/terms with their descriptions:

$siteurl = home_url('/');
$tax = 'region';  // slug of taxonomy

$terms = get_terms($tax);
foreach ($terms as $term) {
    $slug = $term->slug;
    $description = $term->description;
    $link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";

    echo $link;
    echo '<p>' . $description . '</p>';
}

The documentation for the Category Images Plugin says "Use [the function] to get the url and put it in any img tag in category or taxonomy template.

Is it possible to get the image urls in my existing code even though it's a regular page and not a category or taxonomy template file?

Any help or direction would be much appreciated as I'm not sure where to even start.

2

Untested, but something like this should work.

$siteurl = home_url('/');
$tax = 'region';  // slug of taxonomy
$terms = get_terms($tax);
foreach ($terms as $term) {
    $id = $term->term_id;
    $slug = $term->slug;
    $description = $term->description;
    $image_url = z_taxonomy_image_url( $id, NULL, TRUE );
    $link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";

    echo $link;
    echo '<p>' . $description . '</p>';
    echo '<img src="' . $image_url . '">';
}

2nd argument of z_taxonomy_image_url() is image size and 3rd argument is for returning placeholder image.

  • Thanks. It's working...sort of :) It's only loading the placeholder image for all of the categories. I changed "NULL" to "thumbnail", "medium", "large" but no change. Any ideas? – codeview Jan 30 '15 at 20:53
  • Just tested and it works for me. Are you sure you've uploaded images to your terms? – Duane Jan 31 '15 at 11:03
  • Very sorry, I did not see that you had added $id = $term->term_id;. After seeing your answer I only added the $image_url lines. Copying and pasting the whole chunk of code works! Thank you for your time and answer. – codeview Jan 31 '15 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.