Home › Forum › Plugin e temi di WP › Woocommerce Estrarre Immagine di Categoria
-
AutorePost
-
-
10 Marzo 2017 alle 14:44 #31318robyonePartecipante
Ciao Ragazzi, sto creando un sito web in WordPress 4.7.3 e WooCommerce 2.6.14. Nella pagina che mostra le categorie e le sottocategorie devo estrarre la relativa immagine. Ho impostato il tutto in questo modo (è la parte conclusiva del codice):
<?php foreach($parentcat as $key => $val){
?>
<div class="col-md-4 col-lg-4 col-sm-4 text-center">
">
<div class="bordo-nostre-aree text-center" href="#"><h4 class="titolo-macroarea"><?php echo $key; ?></h4></div>
<div class="altezza-20"></div>
</div>
<?php
}
?>
ma non mostra nessun immagine, come posso risolvere?
grazie in anticipo
-
10 Marzo 2017 alle 16:46 #121370SteveAglAmministratore del forum
speiga come mostrare uan singola immagine di una singola categoria adattabile facilmente mettendola nel to foreach
-
11 Marzo 2017 alle 14:11 #121374robyonePartecipante
Ciao SteveAgl, grazie per la risposta purtroppo non risolve il mio problema.. per una maggiore chiarezza allego il codiice della mia pagina
<?php
get_header();
global $product;
$cate = get_queried_object();
$slug = $cate->slug;
$term_id = $cate->term_id;
function woocommerce_subcats_from_parentcat_by_ID($term_id) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 1,
'parent' => $term_id,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
foreach ($subcats as $sc) {
$thumbnail_id = get_woocommerce_term_meta( $sc->term_id, 'thumbnail_id', true );
$subcat[$sc->name] = array(get_term_link( $sc->term_id, 'product_cat' ),$image);
}
//echo "";
//print_r($subcat);
return $subcat;
}
$parentcat = woocommerce_subcats_from_parentcat_by_ID($term_id);
?>
<body>
<div class="container">
<?php woocommerce_breadcrumb(); ?>
<div class="altezza-20"></div>
<?php
wc_print_notices();
do_action( 'woocommerce_before_cart' );
?>
</div>
<div class="container">
<div class="row">
<div class="altezza-20 col-md-3" z-index="-1" >
<!-- sidebar -->
<?php wp_nav_menu( array( 'theme_location' => 'max_mega_menu_3' ) ); ?>
<!-- /sidebar -->
</div>
<!-- blocco centrale -->
<!-- prodotto disponibile -->
<div class="col-md-9 text-justify">
<?php
if(count($parentcat) == 0){ ?>
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'product',
'posts_per_page' => 6,
'product_cat' => $slug,
'paged' => $paged
);
$custom_query = new WP_Query( $custom_args );
?>
<?php if ( $custom_query->have_posts() ) : ?>
<div class="row">
<div class="col-md-6" style="padding-left: 30px;">
<div class="altezza-20"></div>
</div>
<div class="col-md-6 text-right" style="padding-right: 30px;">
<div class="altezza-20"></div>
<?php
if (function_exists(custom_pagination)) {
custom_pagination("","",$paged);
}
?>
</div>
</div>
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<?php do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<?php
// Availability
//$availability = $product->get_availability();
$availability_html = empty( $availability ) ? '' : '<p class="stock ' . esc_attr( $availability ) . '">' . esc_html( $availability ) . '</p>';
echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability, $product );
?>
<?php if ( $product->is_in_stock() ) : ?>
<?php //if ( $product->is_in_stock() ) { ?>
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
">
<div class="altezza-25"></div>
<div class="col-md-4 col-lg-4 col-sm-4">
<div class="altezza-5"></div>
<?php
$product = new WC_product($loop->post->ID);
//echo $product->get_image(array( 230, 230 ));
echo the_post_thumbnail( 'prodotti-categoria' );
?>
<div class="altezza-5"></div>
<?php the_title( '<h4 itemprop="name" class="text-center titolo-prodotto">', '</h4>' ); ?>
<div class="altezza-15"></div>
<!-- versione desktop -->
<div class="visible-lg">
<div class="altezza-15"></div>
<div style="float:left; display:block; padding-left: 0px;">/icone/check.png" width="25px"></div>
<div style="padding-left: 50px;"><p class="text-center prod-disponibile-varianti"> Prodotto disponibile </p></div>
<div style="clear:both;"></div>
</div>
<!-- / versione desktop -->
<!-- versione mobile -->
<div class="visible-xs text-center">
<div class="altezza-15"></div>
<div class="altezza-40"></div>
<div style="float:left; display:block; padding-left: 13px;">/icone/check.png" width="20%"></div>
<div style="padding-left: 50px;"><p class="text-center prod-disponibile-varianti"> Prodotto disponibile </p></div>
<div style="clear:both;"></div>
</div>
<!-- versione mobile -->
<p class="text-center altezza-20">
<?php
get_template_part('btk-parts/price')
?>
</p>
<!-- pulsanti -->
<div class="visible-lg row">
<div class="col-md-3">
<!-- <span data-product-type="< ?php echo $product->product_type; ?>" href="< ?php echo esc_url( add_query_arg( 'add_to_wishlist', the_ID() ) )?>" rel="nofollow" data-product-id="< ?php echo the_ID() ?>" class="btn btn-primary"></span> -->
" rel="nofollow" data-product-id="<?php echo the_ID() ?>" data-product-type="simple" class="wishlist-btn">
<div class="btn-primary">
</div>
</div>
<div class="hidden-md hidden-lg altezza-5"></div>
<div class="col-md-9" style="padding-left: 47px;">
<input type="hidden" name="add-to-cart" value="<?php echo the_ID() ?>" />
<button type="submit" class="single_add_to_cart_button btn-aggiungi-carrello-categoria alt">
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
<?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</div>
</div>
<div class="altezza-20"></div>
<!-- / pulsanti -->
<!-- pulsanti mobile -->
<div class="visible-xs row">
<div class="hidden-md hidden-lg altezza-5"></div>
<div class="col-md-12 text-center" style="padding-left: 47px;">
<input type="hidden" name="add-to-cart" value="<?php echo the_ID() ?>" />
<button type="submit" class="single_add_to_cart_button btn-aggiungi-carrello-categoria alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</div>
</div>
<div class="altezza-20"></div>
<!-- / pulsanti mobile-->
</div>
</form>
<?php endif;?>
<?php endwhile; //end of the loop. ?>
<?php wp_reset_postdata(); ?>
<div class="row">
<div class="col-md-6" style="padding-left: 30px;">
<div class="altezza-20"></div>
</div>
<div class="col-md-6 text-right" style="padding-right: 30px;">
<div class="altezza-20"></div>
<?php
if (function_exists(custom_pagination)) {
custom_pagination("","",$paged);
}
?>
</div>
</div>
<?php else: ?>
<p><?php _e( 'Nessun Prodotto Da Mostrare' ); ?></p>
<?php endif; ?>
<!-- / prodotto disponibile -->
<?php }else{ ?>
<?php foreach($parentcat as $key => $val){
?>
<?php
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo 'name . '" />';
}
}
}
?>
<div class="col-md-4 col-lg-4 col-sm-4 text-center altezza-20">
">
<div class="bordo-nostre-aree text-center" href="#"><h4 class="titolo-macroarea"><?php echo $key; ?></h4></div>
<div class="altezza-20"></div>
</div>
<?php }
}
?>
</div>
<!-- / blocco centrale -->
</div>
</div>
<!-- / box con prodotti -->
<div class="altezza-50"></div>
<div class="container">
<?php
echo woocommerce_output_related_products();
?>
</div>
<div class="altezza-50"></div>
<div class="container">
<div class="row">
<div class="col-md-12">
<?php
get_template_part('btk-parts/box-informativi')
?>
</div>
</div>
</div>
<?php get_footer( 'shop' ); ?>
-
12 Marzo 2017 alle 7:51 #121377SteveAglAmministratore del forum
Primo il regolamento vieta di postare blocchi di codice ma di usare servizi appositi.
Secondo secondo te io mi metto a studiare tutte quelle righe di codice per altro non commentate?
Fai un po’ di debug le indicazioni che ti ho fornito linkando l’alrticolo dovrebbero bastare
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.