custom taxonomy - How to show category images (from plugin) on a regular page (page-example.php)?

I am trying to use the Category Images Plugin to show images with my Custom Taxonomy (Region) categoriesterms. Here is

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.

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.

Share Improve this question asked Jan 30, 2015 at 5:22 codeviewcodeview 4551 gold badge13 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745423081a4627054.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信