Sometimes things that should be easy are hard…
Today, I needed to display an Advanced Custom Fields (ACF) image on a custom taxonomy page. Here’s the solution:
First, create the image field and apply it to the taxonomy like this:
Make sure you have the image field set to output the “Image Array” like this:
Now, go to your taxonomy term and add an image like this:
Finally, copy-and-paste code to your functions.php:
add_action( 'loop_end', 'output_before_taxonomy_loop' );
function output_before_taxonomy_loop(){
if (is_tax()) {
// Display the artist image
$queried_object = get_queried_object();
$taxonomy = $queried_object--->taxonomy;
$term_id = $queried_object->term_id;
$terms = get_field( 'artist_image', $taxonomy.'_'.$term_id);
if( $terms ) {
echo '<img src="'. $terms['url'] .'">';
} else {
//do nothing
}
}
}
Finally, bask in the glory that is Advanced Custom Fields’ taxonomy image fields!
Ain’t life grand? Well…mostly?
More posts from themightymo.com
Simple Pull Quote WordPress Plugin Update!
I just updated our Simple Pull Quote WordPress plugin to include an external style sheet that you can edit. The plugin is simple and completely customizable via CSS. It uses shortcode and custom fields that make it easy to control where the pull quotes will go.
PC Web Blogging for Beginners Class Tonight!
Tonight, I will be teaching a class for folks who are interested in learning more about blogging. The class, titled PC Web Blogging for Beginners, is offered at Minneapolis’ Washburn High School via Minneapolis Community Education‘s Adult Enrichment program. Anyone can register for only $15. I am excited to be participating in this exciting venture! …
WordPress Pull Quote Plugin
I discovered today that there is not a pull quote plugin for WordPress that does what I would like it to do. So, I have begun developing one myself. This is my first attempt at a plugin, and so far it has been a great learning experience (read: lots and lots of failures). haha! I…