使自定义字段显示在wordpress的类别数组上

时间:2019-01-22 02:26:47

标签: php wordpress advanced-custom-fields

我想知道如何在此类别数组上使用一些类别自定义字段,使用当前代码,仅打印类别术语。

<?php
        $terms = get_terms('productcat');
        foreach ($terms as $key => $term) {
        $link = get_term_link($term);
        $cat_ttl =the_field('cat_ttl');
        $cat_img =the_field('featured_image');
        echo '<li>
                <a href="'.$link.'">
                  <div class="imager"><img src="'.$cat_ttl.'" alt="商品"></div>
                  <div class="right">
                     <h3>'.$cat_ttl.'</h3>
                     <p class="det">'.$term->slug.'</p>
                  </div>

                </a>
             </li>';
        }
      ?>

1 个答案:

答案 0 :(得分:0)

我找到了正确的语法:

<?php
          $terms = get_terms('productcat');
          foreach ($terms as $key => $term) {
            $link = get_term_link($term);
            $image = get_field('featured_image', $term);
            $cat_ttl =get_field('cat_ttl', $term);
            echo '<li>
              <a href="'.$link.'">
                <div class="imager"><img src="'.$image.'" alt="商品"></div>
                <div class="right">
                  <h3>'.$cat_ttl.'</h3>
                  <p class="det">'.$term->slug.'</p>
                </div>

              </a>
            </li>';
          }
            ?>