Home › Forum › Problemi Vari con WP › Mostrare sottocategorie della categoria corrente
-
AutorePost
-
-
23 Giugno 2009 alle 13:48 #10798LupinPartecipante
Ciao a tutti.
Ho un tema che utilizza una barra laterale non widgettizzata.
Nel menu Categorie ( che altrimenti verrebbe lunghissimo ) ho nascosto le sottocategorie (depth=1 ) e vorrei che quando seleziono una categoria , potessi visualizzare in un sottomenu le sottocategorie …
Ho provato con questo :
<h3><?php _e(‘Sottocategorie’,’branfordmagazine’);?></h3>
<ul class=”subnav”>
<?php if(is_category()){
$mycat = end(get_the_category());
$current =$mycat->cat_ID;
$current_name = $mycat->cat_name;
?><h4><?php echo $current_name . “<br>”;
?></h4><?php echo “ha le seguenti sottocategorie :”;
wp_list_categories(‘orderby=name&show_count=1&title_li=&use_desc_for_title=1&child_of=’. $current);
}?>
Ma se in un primo momento pareva funzionare , con diverse sottocategorie sembra non individuare la categoria corrente : nome e ID sono di una delle sue sottocategorie e naturalmente dice : nessuna categoria !
Qualche idea ?
C’è un altro metodo per rilevare la categoria corrente ?
Lupin
-
23 Giugno 2009 alle 15:21 #66525SteveAglAmministratore del forum
tu non sai se la categoria che vedi è una madre o una figlia, con get_category_parents puoi avere l’elenco delle madri separato in una stringa da /
http://xref.yoast.com/2.8/nav.html?_functions/get_category_parents.html
il codice si complica perchè devi vedere se la categoria corrente ha un padre nel caso è una figlia quindi devi trovare l’ID della categoria madre con get_cat_id
http://xref.yoast.com/2.8/nav.html?_functions/get_cat_id.html
passandogli il nome altrimenti la categoria non ha madre e quindi è a sua volta una madre ed il tuo codice va bene, insomma va complicato un po’… forse c’è una soluzione più semplice ma non i viene in mente al momento.
-
23 Giugno 2009 alle 15:53 #66528LupinPartecipante
Bè , io dò uno sguardo ogni tanto al forum …
Del resto, se io nel menù principale “nascondo” le sottocategorie ( ho solo 2 livelli ) , quando clikko su una categoria è SICURAMENTE una categoria madre no?
Comunque continuo a studiarci … anche se sto iniziando sol ora con WordPress e “provengo” da Xoops.
Grazie comunque della risposta e dei consigli
Lupin
-
24 Giugno 2009 alle 0:48 #66543LupinPartecipante
Sostituendo a (1) end(get_the_category())
la semplice (2) get_the_category()
ottengo lo stesso identico risultato di : (3) wp_list_categories()
quindi (2) non mi da la categoria CORRENTE , ma nemmeno con la (1) in quanto continua in pratica a … darmi i numeri …
Io mi chiedo : ma se quando clikko una categoria , mi lista i suoi posts con tanto di titolo … come è possibile che non ci possa essere una funzione semplice per catturarla???
Grazie
Lupin
-
24 Giugno 2009 alle 1:25 #66544
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.