循环案例-大循环分类小循环分类文章

Published
April 25, 2022
浏览次数 :  3

<?php get_header(); ?>

<!-- page banner -->
<?php page_banner('text-danger',array(
  'title'  => '设计工具箱'


)) ?>

<!-- end of page banner -->
<?php 
global $post;
//get_object_taxonimes 加参数objects的话就可以显示Object的所有内容 get_object_taxonomies($post,'objects')
  $taxonomies = get_object_taxonomies($post);

  $hilink_terms = get_terms( array(
    'taxonomy' => $taxonomies,
    'hide_empty'  => false
  ) );

 $i = 0;
 foreach ($hilink_terms as $term) { $i++; $bg_class = ($i % 2 != 0) ? 'bg-faded-info' : '' ?>

  <!-- hilink section  -->
      <section class="mt-4 pt-lg-5 pt-4 pb-4 <?php echo $bg_class; ?> bg-repeat-0 bg-position-center-x">
        <div class="container">
          <!-- hilink button -->
        <div class="row mb-4 button-container">
            <a href="javascript:void(0)" class="btn d-block btn-primary nav-link w-20 text-white text-decoration-none"><?php echo $term->name ?></a>
        </div>
        <!-- hilink category content -->
        <div class="row mt-5 button-content hilink-content py-2">

          <?php 
          $hiquery = new WP_Query(array(
            'posts_per_page' => -1,
            'tax_query'  => array(
              array(
                'taxonomy'  => $term->taxonomy,
                'field'  => 'term_id',
                'terms'  => array($term->term_id)

              )
            ),
          ));
          while($hiquery->have_posts()) : $hiquery->the_post();


           ?>
              <!-- hilink item -->
            <div class="url-card col-md-3 d-flex">
              <div class="hilink-icon px-2 d-flex align-items-center">
                <i class="h2 ci-star-filled"></i>
              </div>
              <div class="hi-link-body">
                <a href="<?php echo get_post_meta( get_the_ID(), 'hilink_url',true ); ?>" class="hilink-link text-decoration-none">
                  <h5 class="hilink-title mb-0"><?php the_title(); ?></h5>
                <p class="mute hilink-desc lh-1"><?php echo get_post_meta(get_the_ID(),'hilink_desc',true); ?></p>
                </a>
              </div>
            </div>
          <!-- end of hilink item -->
          <?php endwhile;wp_reset_postdata(); ?>
         
          <!-- end of hilink item -->
          
        </div>
        </div>
      </section>
  <!-- endof hilink section -->


  <?php 

 }
  
 ?>

Top