newbie to writing PHP here. Many hours of searching and don’t know if I’m looking in the right places.

I have a custom taxonomy (directory) with custom post categories for the listings.

I am using Advanced Custom Fields to add an image to each custom category (directory-image).

I am currently displaying the custom categories perfectly fine within a custom directory page template using the code below.

$cat = get_query_var('cat'); $args = array(
'orderby' => 'id',
'child_of' => $cat,
'hide_empty' => 0,
'taxonomy' => directory_categories 
); 
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link( $category->term_id ) . '" class="cat-icon-view">' . "n";
echo '<img src=" " width="90%" height="164"></img>' . "n";
echo '  <h5>' . $category->name . '</h5>' . "n";
echo '</a>' . "n";
}$

It has space to put the image, however I am not confident at writing php markup to include the image that is outputted from the custom image field under the custom category.

<?php the_field('directory-image', false); ?>

I have read many pages on writing PHP within PHP but I wasn’t able to make it work and I’m sure there’s a better way: Help!

Write PHP code in PHP
How to write php within html within php?
Display Categories with Image in Multiple Pages of Homepage – Magento

Read more here: wordpress display categories with image


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: