繁体   English   中英

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

[英]Make custom fields appear on category array, on wordpress

我不知道如何在此类别数组上使用一些类别custome字段,使用当前代码,仅显示类别术语。

<?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>';
        }
      ?>

我找到了正确的语法:

<?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>';
          }
            ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM