php – I want to show image from custom field image on my custom page template

Question

I have created a taxonomy and in that taxonomy i have created custom field for image. Now I want to show that custom field image on my custom page template with category name. I have tried much it is not working.
My code is here below:

    <?php
// Template Name:Post By Category
    get_header(); 

    ?>

<?php

// Get all the categories
$categories = get_terms( 'newcategory' );


// Loop through all the returned terms
foreach ( $categories as $category ):

    // set up a new query for each category, pulling in related posts.
    $services = new WP_Query(
        array(
            'post_type' => 'postlinks',
            'showposts' => -1,
            'tax_query' => array(
                array(
                    'taxonomy'  => 'newcategory',
                    'terms'     => array( $category->slug ),
                    'field'     => 'slug'
                )
            )
        )
    );
?>





<div class=" category_card-div d-lg-inline d-sm-block" stylle="height:450px;">
    <div class=" p-0 text-white category_custom_card d-lg-inline-block d-sm-block"
        style="border: 1px solid #fff;height:450px; border-radius :15px; overflow:hidden; background:#000;width: 22%;">
        <div class="category_card_title bg-danger d-flex align-items-center justify-content-center"
            style="height: 80px;">
            <h3 class="text-white text-center">
                <?php echo $category->name; ?>




                <?php if( get_field('favicon') ): ?>
                <img class="post-icons-custom" style="width: 25px; height: 25px;"
                    src="<?php echo get_the_field('favicon'); ?>" />
                <?php endif; ?>

        


            </h3>
        </div>
        <ul class=" custom-post-list">
            <?php while ($services->have_posts()) : $services->the_post(); ?>
            <li>
                <?php if( get_field('favicon') ): ?>
                <img class="post-icons-custom" style="width: 25px; height: 25px;"
                    src="<?php the_field('favicon'); ?>" />
                <?php endif; ?>
                <a class="text-white ml-2" href="<?php the_permalink(); ?>" sytle="hover:text-decoration: none;">
                    <?php the_title(); ?></a>
            </li>
            <?php endwhile; ?>
        </ul>
    </div>
</div>

<?php
    // Reset things, for good measure
    $services = null;
    wp_reset_postdata();

// end the loop
endforeach;
?>
<?php get_footer(); ?>

Now i want to show like that in the image below:

enter image description here

0
Abdul Rasheed 1 week 2023-01-20T00:20:23-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse