###### tags: `wordpress`,`php`,`term`,`抓取分類列表`
# 🔍wordpress 取得 terms 資訊👊
---
## 取得當前頁面的 term 資訊
### single.php
```php=
$terms = get_the_terms($postID, 'taxonomy名稱');
```
💬說明:主要是在 single 頁面抓取
## 開啟自定義 term 的 options 選單
### single.php
```php=
/**後台cptui自定義 option(有裝cptui才能開啟) */
acf_add_options_page(array(
'page_title' => 'Products options',
'menu_title' => 'Products Options',
'menu_slug' => 'options-products',
'capability' => 'edit_posts',
'parent_slug' => 'edit.php?post_type=products',
'position' => false,
'redirect' => false,
'post_id' => 'products-options',
));
```
## 取得自定義 term 的 options 資料
### single.php
```php=
$footer_information = get_field('footer_information', $stdPostType . '-options');
```
💬說明:主要是在 single 頁面抓取
## 取得自定義 term 的連結
### all.php
```php=
<?php
$link = $list['link'][0];
$termLink = get_term_link($link->term_id, $link->taxonomy);
?>
```
💬說明:主要是在 single 頁面抓取
## 獲取分類縮圖
### all.php
```php=
<?php
foreach ($term_list as $term) {
// 获取分类的缩略图
$thumbnail_url = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image_url = wp_get_attachment_url($thumbnail_url);
if (!empty($thumbnail_url)) {
// 显示分类名称和缩略图
echo '<h2>' . $term->name . '</h2>';
echo '<img src="' . $image_url . '" alt="' . $term->name . '">';
}
}
?>
```
💬說明:獲取分類縮圖
## 取得全部的 term 資訊
### all.php
```php=
$term_list = get_terms(array(
'taxonomy' => $stdTaxonomy,//taxonomy名稱
'parent' => $stdTermId,//父層資訊,例如:0
'hide_empty' => false,
));
```
💬說明:取得所有 term 資訊
## archive 頁面 取得全部的 term 資訊
### all.php
```php=
$footer_information = get_field('footer_information', $stdTaxonomy . '_' . $stdTermId);
));
```
💬說明:$footer_information = get_field({acf slug}, {taxnomy 名稱} . '_' . {term ID});