Home › Forum › Problemi Vari con WP › Visualizzare articoli di una categoria nella sidebar
-
AutorePost
-
-
30 Agosto 2007 alle 10:06 #4449oruxPartecipante
Ciao a tutti,
vorrei visualizzare nella sidebar una voce aggiuntiva alla normale lista delle categorie, in cui poter elencare tutti gli articoli appartenenti a una particolare categoria e soltanto questi.
In poche parole:
CATEGORIE (normale lista sopra)
cat 1
cat 1_a
cat 1_b
cat 1_c
cat 2
cat 2_a
cat 2_b
cat 2_c
cat 3
cat 3_a
cat 3_b
cat 3_c
CATEGORIA 1 (lista speciale per la sola categoria 1 con sottocategorie e articoli)
cat 1_a
cat 1_a_1
art_1
art_2
art_3
cat 1_a_2
art_1
art_2
art_3
cat 1_a_3
art_1
art_2
art_3
cat 1_b
cat 1_b_1
art_1
art_2
art_3
cat 1_b_2
art_1
art_2
art_3
cat 1_b_3
art_1
art_2
art_3
cat 1_c
cat 1_c_1
art_1
art_2
art_3
cat 1_c_2
art_1
art_2
art_3
cat 1_c_3
art_1
art_2
art_3
Quali sono gli argomenti che devo dare a wp_list_cats
Ho letto la pagina http://www.wpitaly.it/wiki/Main/WpListCats
ma ho bisogno di qualche esempio per chiarirmi le idee sull’uso degli argomenti.
Grazie a tutti
-
31 Agosto 2007 alle 23:21 #46425UncinoPartecipante
Allora, poniamo che tu abbia ad esempio 5 categorie.
Vuoi mostrare, nella sidebar, solo i post delle categorie 1 e 3.
Devi scrivere questo:
-
<?php
wp_list_categories(‘orderby=name&include=1,3’); ?>
Abbiamo messo per prima cosa il tag wp_list_categories (che è quello nuovo dalla versione 2.1, mentre wp_list_cats, anche se ancora funzionante, è deprecato), e poi abbiamo messo alcuni parametri per indicare a WordPress che
a. deve ordinare le categorie per nome
b. deve includere solo le categorie con ID 1 e 3
altri esempi qui: http://codex.wordpress.org/Template_Tags/wp_list_categories
-
1 Settembre 2007 alle 11:48 #46438oruxPartecipante
Grazie uncino,
il tag che mi hai suggerito è molto interessante.
Intanto l’ho usato per sostituirlo al deprecato wp_list_cats (proprio nella sidebar).
Questo:
Code:- <h2>Categorie</h2>
-
<?php wp_list_cats(‘sort_column=name&optioncount=1&hierarchical=0’); ?>
Diventa questo:
Code:<?php wp_list_categories(‘orderby=name&title_li=<h2>Categorie</h2>’ ); ?>Purtroppo, però, il tag permette di visualizzare soltanto l’indice delle categorie senza mostrare anche gli articoli.
Ho scoperto anche una cosa insolita.
Scriviamo
Code:?php wp_list_categories(‘orderby=name&include=3’ ); ?>Se la categoria 3 è un categoria madre, senza subordinate (figlie), allora
“include” funziona correttamente.
Se la categoria 3 è una categoria figlia, oppure ha subordinate, allora
“include” non funziona e visualizza la dicitura “Senza categoria”.
Per mostrare gli articoli di una categoria ho risolto con un mini-loop:
Code:<?php if ( is_category(‘NOME_CATEGORIA’) ) { ?>- <h2>INTESTAZIONE</h2>
- <?php echo the_category(‘,’); ?>
-
<?php query_posts(‘category_name=NOME_CATEGORIA & showposts=10000 & orderby=date & order=ASC’); ?>
- ” title=”Leggi: "<?php the_title(); ?>"”><?php the_title(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php endwhile; ?><?php endif; ?>
Le cose si complicano quando ci sono sottocategorie, perché non posso usare questo codice:
Code:- <?php echo the_category(‘,’); ?>
che mostra il link alla categoria che si sta visualizzando.
Lo devo sostituire con:
Code:- /?cat=ID_DELLA_CATEGORIA” title=”Visualizza tutti gli scritti archiviati in: "NOME_DELLA_CATEGORIA"”>NOME_DELLA_CATEGORIA
C’è un modo più pulito?
- <h2>Categorie</h2>
-
1 Settembre 2007 alle 12:53 #46439oruxPartecipante
Scusate il casino…
Non sono riuscito a scrivere il codice sul forum
Altro che apici rovesci?
Se mi spiegate come fare, riposto il codice in modo corretto.
Grazie
-
3 Settembre 2007 alle 3:52 #46450UncinoPartecipante
mmm, prova a vedere se questo plugin fa al caso tuo:
-
26 Giugno 2008 alle 9:13 #55198MetalDavePartecipante
Questa discussione mi interessa molto, però mi sono un pò perso, ho necessità di visualizzare sulla sidebar, l’elenco delle categorie e per ogni categoria gli utlimi tre articoli pubblicati…non capisco come realizzarlo…help me
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.