Support

Account

Home Forums General Issues Category Page with ACF. How do I display the ACF?

Solved

Category Page with ACF. How do I display the ACF?

  • Hey all.
    I am ramming my head against a wall believing I am missing something crucial.

    I have a created a category in the posts called ‘shoes’ and was asked to make it so I could also display a custom image and formatable text on the archive page for the category. I worked out how to add the ACF to the Category page but cannot for the life of me work out how to display it in the archive page. It has to be dynamic so it can work with all of the categories. I would have thought that you would just say:
    <?php the_field('category_image'); ?> but that is for a post. I tried to inject the term_id into the php but that was wrong.

    Any ideas. Would be really appreciative.

    Props

  • I’ve just had to do the same thing displaying the image url and this is how IO did it…

    
    <?php if(get_field('cat_image', 'category_'. the_category_ID( $echo ) .'')) { ?>
    <?php the_field('cat_image', 'category_'. the_category_ID( $echo ) .''); ?>
    <?php endif; ?>
    

    This worked for me.

  • Hi. Just realised that the above code is incorrect as that doesn’t get the current category’s ID. This should work…

    
    <?php 
    $category = get_category( get_query_var( 'cat' ) );
    $cat_id = $category->cat_ID;
    if(get_field('cat_image', 'category_'. $cat_id .'')) { ?>
    <?php the_field('cat_image', 'category_'. $cat_id .''); ?>
    <?php endif; ?>
    
  • A massive thank you daretothink. Much appreciation!
    (And apologies for taking so long to get back to your message).
    All the best.

  • Thank you so much for this topic. I’ve spent a week trying to figure this out and read lots of similar topics but this worked perfectly. thank you.
    Kieran

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.