• coxuso

    (@coxuso)


    Hi,

    I’m using woocommerce with my wordpress site, all newest version. I wanna display only two product categories on my webpage. Like i wanna display the categori picture, not the products in it. How can i do this? I’ve been searching the whole day without luck!

Viewing 1 replies (of 1 total)
  • Clarion Technologies

    (@clarionwpdeveloper)

    use below code , you will get two categories images with link
    If you don’t want display link remove anchor tag around image and title also

    <?php
    $args = array(
    		'number'     => 2,
    		'order'      => 'ASC',
    		'hide_empty' => 1,
    );
    
    $Post_Count = 1;
    
    $product_categories = get_terms( 'product_cat', $args );
    $count = count($product_categories);
    
    if ( $count > 0 ){
    
        foreach ( $product_categories as $product_category ) { ?>
    
    	<?php $wthumbnail_id = get_woocommerce_term_meta( $product_category->term_id,'thumbnail_id', true );
               $wimage = wp_get_attachment_url( $wthumbnail_id );?>
    
             <a href="<?php echo get_term_link( $product_category ); ?>">	
    
    			<?php if($wimage){?><img width="300" height="300" src="<?php echo $wimage?>"><?php } else {?><img width="300" height="300"  src="<?php echo site_url();?>/wp-content/plugins/woocommerce/assets/images/placeholder.png"><?php  }?>
    
    						<h3><?php echo $product_category->name; ?> <mark class="count">(<?php echo $product_category->count;?>)</mark>		</h3>
    		</a>
    
    		<?php $Post_Count++; ?>	
    
    <?php  }
    } ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Display only a specifik product categori on homepage’ is closed to new replies.