Home › Forums › General Issues › Category Images not displaying
What I’m trying to accomplish is I’ve added a custom field to upload an image for categories. I’m trying to get that category image to show up. The page: http://104.130.179.56/~mynewcastle/category/casino/
the code:
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories('child_of=39', $args);
foreach($categories as $category) { ?>
<h3><a href="<?php get_category_link( $category->term_id ) ?>" title="<?php sprintf( __( "View all posts in %s" ), $category->name ) ?>" /><?php echo $category->name ?></a> </h3>
<img src="<?php echo do_shortcode( '[acf field="featured_category_image" post_id="' . the_category_ID() . '"]');?>" />
<?php } ?>
I can’t for the life of me figure out why it’s not working. In the output code it just pulls <img src="25" />
not the full like of the image for each category
What is you change this
[acf field="featured_category_image"
to this
[acf field="featured_category_image['url']"
? 🙂
That did not solve the issue for me. Still working on a solution.
I figured it out. Here is my code…
<section>
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories('child_of=39', $args);
foreach($categories as $category) { ?>
<div class="casino-games">
<?php $image_url=get_field('featured_category_image', $category); ?>
<a href="<?php get_category_link( $category->term_id ) ?>" title="<?php sprintf( __( "View all posts in %s" ), $category->name ) ?>" />
<h3><?php echo $category->name ?></h3>
<img src="<?php echo $image_url ?>" /> </a> </div>
<?php } ?>
<div class="clear"></div>
</section>
it was this part that did the trick for me…
<?php $image_url=get_field('featured_category_image', $category); ?>
I know this thread is aging, but any help would be greatly appreciated.
I have a similar problem, which I cannot seem to locate a solution for in the documentation or forum, but this looks as close as I can get so far.
I have a default category.php template and have added the following code to it to display my category icon, which works on the index.php page of my site just perfectly.
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) { ?>
<?php echo $image_url=the_field('event_type_category_icon', $category); ?>
<img src="<?php echo $image_url=the_field('event_type_category_icon', $category); ?>" />
<?php }
?>
But when I want to display the specific category icon on its coordinating category page, it displays an image ID instead of the image URL (which would reflect the image itself) and shows that the image is coming from the actual /category/ directory as well which is not true.
Please help!
Michael
The topic ‘Category Images not displaying’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.