Php 我如何获得woocommerce类别标题和afc归档值

Php 我如何获得woocommerce类别标题和afc归档值,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在主页上的主题中,我想显示调用类别名称和两个自定义文件值。我试了这么久,但还没有成功 下面是我的html代码 <li class="wow fadeInDown" data-wow-duration="1.5s" data-wow-delay="0.3s"><a href="#"> <div class="textpos"> <h5>Category Name</h5>

在主页上的主题中,我想显示调用类别名称和两个自定义文件值。我试了这么久,但还没有成功

下面是我的html代码

<li class="wow fadeInDown" data-wow-duration="1.5s" data-wow-delay="0.3s"><a href="#">
          <div class="textpos">
            <h5>Category Name</h5>
            <h6>custom field one</h6>
          </div>
          <div class="imgpos">custom field two</div>
          </a></li>
  • 对于定制文件,我使用AFC 所以自定义字段的一个值可以通过以下方式获得

    <?php the_field('custom_title'); ?>
    
    
    
    自定义字段的两个值可以通过以下方式获得

    <?php 
    
    $image = get_field('image');
    
    if( !empty($image) ): ?>
    
        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    
    <?php endif; ?>
    
    
    “alt=”“/>
    
    下面是我在互联网上得到的代码,它可以显示类别名称,但我不知道如何在那个里应用我的html和AFC值

    <?php
    $args = array(
        'number'     => $number,
        'orderby'    => 'title',
        'order'      => 'ASC',
        'hide_empty' => $hide_empty,
        'include'    => $ids
    );
    $product_categories = get_terms( 'product_cat', $args );
    $count = count($product_categories);
    if ( $count > 0 ){
        foreach ( $product_categories as $product_category ) {
            echo '<h4><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h4>';
            $args = array(
                'posts_per_page' => -1,
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        // 'terms' => 'white-wines'
                        'terms' => $product_category->slug
                    )
                ),
    
            );
    
        }
    }
    
    ?>
    
    
    
    更新1

    bellow是另一个代码,它几乎不能满足我的需要。我想要标题,现在来看看所有的分类标题和所有的产品名称

    <?php
    
    $post_type = 'product';
    
    // Get all the taxonomies for this post type
    $taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
    
    foreach( $taxonomies as $taxonomy ) : 
    
        // Gets every "category" (term) in this taxonomy to get the respective posts
        $terms = get_terms( $taxonomy );
    
        foreach( $terms as $term ) : 
    
            $posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=2" );
    
            if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
              ?>
              <a href="<?php the_permalink(); ?>"><span><?php the_title(); ?></span></a><br><br>
              <?php
            endwhile; endif;
    
        endforeach;
    
    endforeach;
    
    
    ?>