有一个可爱的功能get_term_link()
, 您可以使用它来获取WP_Term
对象存档页URL。
只需将此添加到foreach
回路:
$url = get_term_link( $attribute );
<人力资源>
Edit
由于您需要为每个属性检索特定的元值,请尝试将它们全部提取并var\\u转储,以查看您到底需要什么。
例如:
/** @var \\WP_Term[] $attributes */
$attributes = get_terms( \'pa_couleurs\' );
foreach ( $attributes as $attribute ) {
echo $attribute->name;
// Get all attribute meta data
$meta = get_term_meta( $attribute->term_id );
// Dump it out on the page. Remove after you find the key(s) you need
echo \'<pre>\';
print_r( $meta );
echo \'</pre>\';
// After finding the exact meta key that holds the info you need, edit this
$images = (array) get_term_meta( $attribute->term_id, \'change_this\', true );
// This will probably hold the array of attachment IDs, so you\'ll need to get the URL\'s from that
foreach ( $images as $image_id ) {
// Get image src from ID
$src = wp_get_attachment_image_url( $image_id, \'thumbnail\' );
// If src is found
if ( $src ) {
echo \'<img src="\' . $src . \'" alt="Attribute Image">\';
} // If not
else {
echo \'No image src for the image ID \' . $image_id . \'<br>\';
}
}
}