categories – I want to show the category image (set with ACF) inside a loop that shows it inside the cards, how can I do it?

Question

<?php get_header(); 

$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;

$id_cat = array('parent' => $cat_id);
$categories = get_categories( $id_cat );

// Get particular category’s object info.
$queried_object = get_queried_object();

// (Optional depending on desired outcome) If you wanted to get the type of taxonomy.
$taxonomy = $queried_object->taxonomy;

// (Optional depending on desired outcome) If you wanted to get the associated ID.
$term_id = $queried_object->term_id;

// Get image ID for this field.
$attachment_id = get_field( ‘category_image’, $queried_object );

// URL of image at specific size.
$image = $attachment_id[‘sizes’][‘chosen-image-size’];

?>
<section class="p-5">
    <div class="container">
        <div class="row text-center">
            <h3><?php single_cat_title(); ?></h3>
            <p><?php category_description(); ?></p>
        </div>
    </div>
</section>

<section>
    <div class="container animated">
        <div class="row d-flex" data-masonry='{"percentPosition": true }'>

‘.’
term_id ).'”>’ .$category->name.”.’

‘;
}

?>


In evidenza

            <?php while(have_posts()): the_post(); ?>
                <div class="col-6 col-md-4 col-xl-3 mb-4">
                    <div class="card text-center">
                        <a href="<?php the_permalink() ?>">
                                        <!-- Immagine Articolo -->
                            <?php if(has_post_thumbnail()): ?>  
                                <div class="m-1"><?php the_post_thumbnail('thumbnail') ?></div>
                            <?php endif; ?>
                        </a>    
                        <div>
                            <h3><?php the_title(); ?></h3>
                            <p><?php the_excerpt(); ?></p>
                        </div>
                        <a href="<?php the_permalink() ?>" class="btn btn-outline-dark btn-sm">Continua a
                            Leggere</a>
                    </div>
                </div>
                    <?php endwhile; ?>
                    <?php else: ?>
                        <?php echo wpautop('ops.. non ho trovato nulla');?>
                    <?php endif; ?>
        </div>
    </div>
</section>

0
elia sidori 2 weeks 2021-05-04T19:22:56-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse