我對 wordpress 主題開發非常陌生,我創建了一個自定義帖子和自定義分類法。我已經創建了一個關于分類的影像 acf 現在我想在首頁上顯示所有分類術語及其 acf 欄位。我可以使用get_terms()函式獲取所有術語,但我不知道如何獲取該分類的 acf 欄位。
$terms = get_terms(array(
"taxonomy" => "categories",
"hide_empty" => false ));
foreach($terms as $term):
echo $term->name;
endforeach;
我想要 front-page.php 上該術語的術語名稱和影像 acf 欄位。任何建議都會有所幫助,并提前致謝。
uj5u.com熱心網友回復:
請嘗試此代碼
<?php
$terms = get_the_terms(get_the_ID(), "categories");
if (!empty($terms)): ?>
<ul>
<?php foreach ($terms as $term): ?>
<li class="<?php echo $term->slug; ?>">
<img src="<?php the_field("image_field_name", $term); ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php endif;
?>
有關更多詳細資訊,您可以查看此檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/487981.html
上一篇:帶php的引導卡輪播
