Visualizzare tutte le sottocategorie di una categoria specifica?
2 risposta
- voti
-
- 2013-05-30
Prova qualcosa di simile:
per ID
function woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) { $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $parent_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '<ul class="wooc_sclist">'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>'; } echo '</ul>'; }
di NAME
function woocommerce_subcats_from_parentcat_by_NAME($parent_cat_NAME) { $IDbyNAME = get_term_by('name', $parent_cat_NAME, 'product_cat'); $product_cat_ID = $IDbyNAME->term_id; $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $product_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '<ul class="wooc_sclist">'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>'; } echo '</ul>'; }
<"Modifica:"
Completatoil codice,testato,vederei commenti
Try something like this:
by ID
function woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) { $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $parent_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '<ul class="wooc_sclist">'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>'; } echo '</ul>'; }
by NAME
function woocommerce_subcats_from_parentcat_by_NAME($parent_cat_NAME) { $IDbyNAME = get_term_by('name', $parent_cat_NAME, 'product_cat'); $product_cat_ID = $IDbyNAME->term_id; $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $product_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '<ul class="wooc_sclist">'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>'; } echo '</ul>'; }
Edit:
Completed the code, tested it, see comments
-
Grazie,manon so comeinserire quel codicenelmio,comunque hotrovato questo codice: [http://wordpress.stackexchange.com/questions/73795/how-to-split-the-categories-of-subcategories-with-thumbnails] mamostratutte le categorie,hobisogno di una sola categoria selezionata con le sue sottocategorieThanks, but I don't know how to put that code into mine, anyway I found this code : [http://wordpress.stackexchange.com/questions/73795/how-to-split-the-categories-of-subcategories-with-thumbnails] but it shows All categories, I need just One category selected with its subcategories
- 0
- 2013-05-30
- Yhis
-
Grazie amicomio,l'ho copiatoe incollatonelmio woocommerce-template.phpnellapartein cuine hobisognoper usarlo,mamostratutte le categoriee nessuna sottocategoria;dai un'occhiata al link che hopostato sopra,dovrebbeessere cosìma con una sola categoriae le sue sottocategorieThanks my friend, I copied and pasted it in my woocommerce-template.php in the part where I need it to use, but it displays all the categories and none subcategories; please take a look at the link I posted above, it should be like that but with only one category and its subcategories
- 0
- 2013-05-30
- Yhis
-
Ho dato una rapida occhiata al codice dalle domande che hai collegato.Quello che stai cercando difare èfare solo ciò che è associato a `$ sub_cats=get_categories ($ args2)`e laparte `$ args2=array (...)`,ma detto ciò,ciò che ho suggerito èpraticamente lo stesso.Quindinon sono davvero sicuro delmotivoper cuinonfunzionaperte.I took a quick look at the code from the questions you linked. What you are lloking to do is only do whats associated to `$sub_cats = get_categories( $args2 )` and the `$args2 = array( ... )` part, but that said, what i suggested is pretty much the same. So I'm not really sure why it isn't working for you.
- 0
- 2013-05-30
- Nicolai
-
se rimuovo `function woocommerce_subcats_from_parentcat ($parent_cat) {` funziona,mamostra solo le categorieprincipali,non le sottocategorie,se copioe incolloil codice così com'è,viene visualizzato vuoto,nessuno.if I remove `function woocommerce_subcats_from_parentcat($parent_cat) {` it works, but shows only main categories, not subcategories, if I copy and paste your code as it is, it shows blank, none.
- 0
- 2013-05-30
- Yhis
-
Ok,mostra le sottocategoriee non la categoriaprincipale,ma solo semetto "23",con "21" ètutto vuoto .. grazieperil vostro aiuto,sepoteste correggere questo ultimopiccolobug sarebbefantasticopermeOk, it shows subcategories and not main category, but only if I put '23', with '21' it's all blank.. thanks for your help, if you could fix this last little bug it would be great for me
- 0
- 2013-05-30
- Yhis
-
okfunziona,devo solomostrare la categoriaprincipale sopra le sottocategorie: CATEGORIA PRINCIPALE - cat - catok it works, i need just to show the main category above the subcategories: MAIN CATEGORY - sub cat - sub cat
- 0
- 2013-05-30
- Yhis
-
ok amicomio,funzionatuttobene!moltegrazie!! solo unapiccola domanda: èpossibilemostrare sempre la categoriaprincipale quando clicco su una sottocategoria?ok, my friend, everything works fine! thanks a lot!! just a small question: is it possible to show always the main category when I click on a subcategory?
- 0
- 2013-05-30
- Yhis
-
certamente èpossibile,mami sembra una domanda,chiedilabene;questopotrebbe aiutarti: http://wordpress.stackexchange.com/questions/56784/get-main-parent-categories-for-a-productit certainly is possible, but it seems like a question to me, ask it properly; this might help you: http://wordpress.stackexchange.com/questions/56784/get-main-parent-categories-for-a-product
- 0
- 2013-05-30
- Nicolai
-
siprobabilmente è la soluzionemigliore,ma comeposso chiamare queste duefunzioninellamiapagina?yes probably is the best solution, but how can i call these two functions in my page?
- 0
- 2013-05-30
- Yhis
-
comunqueilproblema rimane ancora: woocommerce_subcats_from_parentcat_by_ID ($parent_cat_ID)mostra solo le sottocategoriee woocommerce_subcats_from_parentcat_by_NAME ($parent_cat_NAME)mostra solo TUTTE le categorieprincipali senza sottotitoli.anyway, the problem still remains: woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) displays only sub categories, and woocommerce_subcats_from_parentcat_by_NAME($parent_cat_NAME) displays only ALL main categories with no sub.
- 0
- 2013-05-30
- Yhis
-
Hobisogno di MAIN-> sube una volta cliccato su sub dovrebbeessere lo stesso delgenitore 'MAIN-> sub'.Hobisogno che questotipo dimenunon cambi se clicco su MAIN o su un subI need MAIN->sub and once i click on sub it should be the same as parent 'MAIN->sub'. I need that this kind of menu doesn't change if I clik on MAIN or a sub
- 0
- 2013-05-30
- Yhis
-
Prima ditutto,entrambe lefunzionifunzionanoperfettamenteperme,forsene stai usando unain modo sbagliato.In secondo luogo,dovrestiesserein grado di ottenereil comportamento desiderato con leinformazioni quie sulla domanda collegata sopra.Inbocca al lupo!First of all, both functions are working perfectly fine for me, you are maybe using one of them wrong. Secondly, you should be able to achieve the wanted behaviour with the information here and on the question linked above. Good luck!
- 0
- 2013-05-30
- Nicolai
-
- 2014-12-11
Eccoil codice che hafunzionatoperme in unmodello dipagina (ilmio IDgenitoreera 7):
<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' => 7, )); foreach($wcatTerms as $wcatTerm) : $wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true ); $wimage = wp_get_attachment_url( $wthumbnail_id ); ?> <div><a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"> <?php if($wimage!=""):?><img src="<?php echo $wimage?>" class="aligncenter"><?php endif;?></a> <h3 class="text-center"><a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a></h3> </div> <?php endforeach; ?>
Here is the code that worked for me in a page template (my parent id was 7):
<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' => 7, )); foreach($wcatTerms as $wcatTerm) : $wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true ); $wimage = wp_get_attachment_url( $wthumbnail_id ); ?> <div><a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"> <?php if($wimage!=""):?><img src="<?php echo $wimage?>" class="aligncenter"><?php endif;?></a> <h3 class="text-center"><a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a></h3> </div> <?php endforeach; ?>
Devomostraretutte le sottocategorie utilizzando
attualmenteio uso:
Vabene mamostra solo la categoriaprincipalee solo una sottocategoria ...
Come risolverlo?