Custom Post Type & Taxonomy – Custom fields in archive template
-
Hi,
I’ve recently dive into Custom Post Types and I’m struggling with taxonomies.
In fact, I create a CPT (‘project’) and its associated taxonomy (‘color’). I also created an archive template for the CPT (‘archive-project.php’) and a ‘taxonomy-color.php’ file to display the projects regarding the ‘color’taxonomy they belong. Then I created different posts with using ‘blue’ and ‘red’ terms.
At this point all is ok. Then I’m trying to display different content (a simple text) at the and of the page if I’m on https://localhost:8888/test/color/blue/ or https://localhost:8888/test/color/red/
I’ve found out a solution using basic php in my ‘taxonomy-color.php’ file like so :
<?php if ( is_tax('color','blue' ) ) {?> <div class="test" style="color: blue">Hello</div> <?php } elseif ( is_tax('color','red' ) ) {?> <div class="test" style="color: red">Hello</div> <?php } ?>
But it’s not really dynamic, so I had a look at the very useful ACF plugin to create a custom field and assign it to the ‘color’ taxonomy. All is ok on the admin side but I can’t find a way to display the value of the custom fields in my template file. The different ways I’ve used fail.
Is anybody has an idea or a different point of view to display different content on a taxonomy archive template?
Thanks by advance for your help.
- The topic ‘Custom Post Type & Taxonomy – Custom fields in archive template’ is closed to new replies.