Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress中分类列表中的分类图像_Wordpress - Fatal编程技术网

WordPress中分类列表中的分类图像

WordPress中分类列表中的分类图像,wordpress,Wordpress,我想列出我的自定义文章类型及其图像的所有类别。我试过很多密码,但都没用。使用这个给定的代码,我将所有类别作为一个列表来获取,但是我没有获取自定义字段的值。谁来帮我做这个 $post_type = 'product'; $tax = 'productcat'; $tax_terms = get_terms($tax); if ($tax_terms) { foreach ($tax_terms as $tax_term) { $args=array( 'post_type' => $p

我想列出我的自定义文章类型及其图像的所有类别。我试过很多密码,但都没用。使用这个给定的代码,我将所有类别作为一个列表来获取,但是我没有获取自定义字段的值。谁来帮我做这个

$post_type = 'product';
$tax = 'productcat';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms  as $tax_term) {
$args=array(
  'post_type' => $post_type,
  "$tax" => $tax_term->slug,
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1
);

$term_id = $tax_term->term_id;
$term_meta = get_option( 'taxonomy_' . $term_id );
$my_cf = $term_meta[ 'category_image' ];
echo $my_cf;
}
}

我想这是这个问题的答案

<?php 
foreach((get_the_category()) as $category) { 
    echo '<img src="http://example.com/images/' . $category->cat_ID . '.jpg" alt="' . $category->cat_name . '" />'; 
} 
?>

另一个答案,也在这里。它可能对你有用

<?php
            $args = array( 'type'                     => 'product',
                           'child_of'                 => 16,
                           'parent'                   => '',
                           'orderby'                  => 'name',
                           'order'                    => 'ASC',
                           'hide_empty'               => 0,
                           'hierarchical'             => 1,
                           'exclude'                  => '',
                           'include'                  => '',
                            'number'                   => '',
                            'taxonomy'                 => 'product_cat',
                            'pad_counts'               => false 
                          ); 
            $categories = get_categories( $args ); 
            foreach($categories as $category):
              $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
              $image = wp_get_attachment_url( $thumbnail_id );
           ?>
              <div class="col-xs-6 col-sm-4 product-box"><a href="#"><img src="<?php echo $image; ?>"></a></div>
           <?php   
            endforeach;
           ?>

非常感谢您的代码, 我用你们的代码得到了答案,我也做了一些修改。这是密码

<div class="row">
<?php   
$post_type = 'product';
$tax = 'productcat';
$args = array( 'type'                     => 'product',
   'parent'                   => '',
   'orderby'                  => 'name',
   'order'                    => 'ASC',
   'hide_empty'               => 0,
   'hierarchical'             => 1,
   'exclude'                  => '',
   'include'                  => '',
    'number'                   => '',
    'taxonomy'                 => 'productcat',
    'pad_counts'               => false 
  ); 
$categories = get_categories( $args ); 
foreach($categories as $category):
$term_id = $category->term_id;
$variable = get_field('category_image', 'productcat_'.$term_id);
$imageURL   =   $variable['sizes']['medium'];
?>
<div class="col-sm-4 alt-no-padding-r-x">
<div class="products_item">
    <div class="product_head">
        <p><?php echo $category->name; ?></p>
    </div>
    <div class="top-img">
        <img src="<?php echo $imageURL; ?>" />
    </div>
    <div class="product_desc">
        <p><?php echo $category->description; ?></p>
    </div>
    <div class="product_list text-left no-decor">
        <ul>
            <?php  
            $args=array(
              'post_type' => $post_type,
              "$tax" => $category->slug,
              'post_status' => 'publish',
              'posts_per_page' => -1,
              'caller_get_posts'=> 1
            );
            $my_query = new WP_Query($args);
            if( $my_query->have_posts() ) {

            while ($my_query->have_posts()) : $my_query->the_post();?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>  </a></li>
            <?php endwhile;
            }
            ?>
         </ul>
    </div>
    <div class="readmore-product no-decor">
        <a href="#">Read More</a>
    </div>
     </div>
   <div class="plan-shadow"></div>
</div>
<?php   
endforeach;
wp_reset_query();
?>  
</div>

" />


mAyUr DeVmUrArI,感谢您的重播,我想这是主要类别,我想要自定义帖子类型的分类列表和图像。我尝试了此代码,但它没有显示任何内容。对于自定义帖子类型,请使用此代码。违抗地获得了您的结果。