Mahdi
Mahdi

Reputation: 216

How to show all categories instead of posts in archive page?

I am trying to show categories in archive page instead of posts which by clicking on category name, show all related posts again in archive page.

<?php 
      $categories = get_categories();
      foreach($categories as $category) {
 ?>          

        <!-- Single gallery Item -->
        <div class="col-12 col-md-6 single_gallery_item entre wow fadeInUp" data-wow-delay="0.2s">
          <!-- Welcome Music Area -->
          <div class="poca-music-area style-2 d-flex align-items-center flex-wrap">

            <div class="poca-music-content text-center">
              <span class="music-published-date mb-2">December 9, 2018</span>
              <h2>
                  <?php echo '<a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a>'; ?>
              </h2>
              <div class="music-meta-data">
                <p>By <a href="#" class="music-author">Admin</a> | <a href="#" class="music-catagory">Tutorials</a> | <a href="#" class="music-duration">00:02:56</a></p>
              </div>
              <div>
                <?php 
                    $category_description = category_description();
                    echo $category_description;
                ?> 
              </div>
            </div>
          </div>
        </div>
        <?php 
          }
        ?>

this is my code for listing categories, but I do not know how to show categories' description and feature images which I added by a plugin by the name of Category featured image.

Upvotes: 1

Views: 1747

Answers (1)

Dmitry Leiko
Dmitry Leiko

Reputation: 4372

This quick example:

$categories = get_categories();
    foreach($categories as $category) {
        $featured_image_id = get_term_meta( $category->term_id, 'featured_image_id', true );
        $category_image = wp_get_attachment_image( $featured_image_id, 'thumbnail' );
        ?>
        <p><?php echo $category->name ?></p>
        <p><?php echo $category->description ?></p>
        <p><?php echo $category_image; ?></p>
        <?php
    }

Hope it help you.

Upvotes: 1

Related Questions