Home › Forum › Problemi Vari con WP › escludere categoria da the_category
-
AutorePost
-
-
31 Marzo 2008 alle 11:07 #6173TremisferoPartecipante
Salve a tutti.
In una visualizzazione compatta degli aritcoli presenti nel mio sito mostro la categoria a cui appartiene ogni singolo articolo con il tag the_category, che mi mostra il nome e le categorie a cui appartiene un articolo, separate da un separatore (virgola).
Esiste un modo semplice (tramite tag) per escludere dalla visualizzazione il link di una specifica categoria estratta da the_category?
-
26 Dicembre 2009 alle 17:46 #70297adedipPartecipante
avrei bisogno della stessa cosa..ovviamente non credo di possa fare con the_category() stando a quanto dice la documentazione..ma sapete se si può fare con qualche altro metodo?!
thx
-
26 Dicembre 2009 alle 20:33 #70298SteveAglAmministratore del forum
Una cosa del tipo (da verificare non l’ho provata)
<?php
// Definire l’elenco degli ID da escludere
$exclude = Array(1, 2, 35)
foreach((get_the_category()) as $category) {
if (!in_array($category->cat_ID, $exclude) {
echo $category->cat_name;
}
}
?>
-
30 Dicembre 2009 alle 13:30 #70359adedipPartecipante
funziona alla grande! ho fatto anche questa modifica (magari a qualcuno serve) per rendere la voce della categoria cliccabile:
(ho usato la viabile “categoryx” perché category mi creava conflitto con altre chiamate presenti nel template)
<?php
// Definire l'elenco degli ID da escludere
$exclude = Array(12);
foreach((get_the_category()) as $categoryx) {
if (!in_array($categoryx->cat_ID, $exclude)) {
echo "-a href='/?cat=$categoryx->cat_ID'- $categoryx->cat_name -/a-";
}
}
?>
ho messo dei trattiti al posto delle parentesi per non far parsare il tag < a >
grazie!`
-
21 Settembre 2010 alle 11:08 #77203albyrizzo90Partecipante
Allora ho seguito l’ultimo codice per rendere la categoria cliccabile. Mi servirebbe però un consiglio: mettendo un separatore (una virgola) dopo $categoryx->cat_name (dunque $categoryx->cat_name,) il separatore viene visualizzato anche dopo l’ultima categoria elencata. Vorrei che l’ultimo separatore non venisse visualizzato appunto. Sapete come si può fare?
-
22 Settembre 2010 alle 19:03 #77223albyrizzo90Partecipante
Ho risolto da me (: a qualcuno potrebbe servire, lo posto:
<?php
//exclude these from displaying
$exclude = array(“NOME CATEGORIA”);
//set up an empty categorystring
$catagorystrings = array();
//loop through the categories for this post
foreach((get_the_category()) as $category)
{
//if not in the exclude array
if (!in_array($category->cat_name, $exclude))
{
$catagorystrings[] = ‘-a href=”‘.get_bloginfo(url).get_option(‘category_base’).’/category/’.$category->slug.'”-‘.$category->name.’-/a-‘;
}
}
echo join(‘, ‘,$catagorystrings);
?>
N.B. ho messo dei trattiti al posto delle parentesi per non far parsare il tag < a >
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.