Wordpress 如何获取分类图像';谁的头衔/名字/鼻涕虫?
使用自定义分类法构建页面, 要调用下面带有名称/标题/slug的图像, 我的代码如上,谢谢帮助Wordpress 如何获取分类图像';谁的头衔/名字/鼻涕虫?,wordpress,acfpro,Wordpress,Acfpro,使用自定义分类法构建页面, 要调用下面带有名称/标题/slug的图像, 我的代码如上,谢谢帮助 <?php $types = get_terms( array( 'taxonomy' => 'material', 'hide_empty' => true, ) ); get_header(); ?> //*html code*// <?php foreach($types as $type) { $image = get_field
<?php
$types = get_terms( array(
'taxonomy' => 'material',
'hide_empty' => true,
) );
get_header(); ?>
//*html code*//
<?php foreach($types as $type) {
$image = get_field('image', 'material_' . $type->term_id . '' );
if ( has_term( $type->term_id, 'material')) {
echo '<img src="' . $image . '" /> ';
}
}?>
//*html代码*//
//*html代码*//
试试这个代码
$terms = get_terms( array(
'taxonomy' => 'market-place',
'hide_empty' => false,
'orderby' => 'term_id',
'order' => 'asc',
) );
foreach ($terms as $terms_row) {
echo "<pre>";
print_r($terms_row);
echo "</pre>";
$terms_row->slug;
}
$terms=get\u terms(数组)(
“分类法”=>“市场”,
“hide_empty”=>false,
'orderby'=>'term_id',
“订单”=>“asc”,
) );
foreach($terms作为$terms\u行){
回声“;
打印(条款行);
回声“;
$terms\u row->slug;
}
我用愚蠢的方法解决了这个问题。如果有更好的方法,请告诉我。:)
//*html代码*//
这是工作代码
$prod\u categories=get\u术语('product\u cat',数组(
'orderby'=>'name',
“订单”=>“ASC”,
“hide_empty”=>true
));
foreach($prod\U类别为$prod\U cat):
$cat\u thumb\u id=get\u woocommerce\u term\u meta($prod\u cat->term\u id,'thumbnail\u id',true);
$shop_catalog_img=wp_get_attachment_image_src($cat_thumb_id,'shop_catalog');
$term_link=get_term_link($prod_cat,'product_cat');?>
对不起,伙计,我想要的是得到分类法的名称/标题/slug:):)这让我打印所有的细节。但我只想用名称显示分类图像:(@kengi我添加了另一个代码。这是我这边的工作:)
$terms = get_terms( array(
'taxonomy' => 'market-place',
'hide_empty' => false,
'orderby' => 'term_id',
'order' => 'asc',
) );
foreach ($terms as $terms_row) {
echo "<pre>";
print_r($terms_row);
echo "</pre>";
$terms_row->slug;
}
<?php
$types = get_terms( array(
'taxonomy' => 'material',
'hide_empty' => true,
) );
get_header(); ?>
//*html code*//
<?php foreach($types as $type) {
$image = get_field('image', 'material_' . $type->term_id . '' );
if ( has_term( $type->term_id, 'material')) {
echo '<img src="' . $image . '" /> ';
}
if ( has_term( $type->term_id, 'material')) {
echo $type->name;
}
}?>
$prod_categories = get_terms( 'product_cat', array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true
));
foreach( $prod_categories as $prod_cat ) :
$cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, 'thumbnail_id', true );
$shop_catalog_img = wp_get_attachment_image_src( $cat_thumb_id, 'shop_catalog' );
$term_link = get_term_link( $prod_cat, 'product_cat' );?>
<a href="<?php echo $term_link; ?>"><img src="<?php echo $shop_catalog_img[0]; ?>" alt="<?php echo $prod_cat->name; ?>" /></a>
<?php endforeach; wp_reset_query();