Home › Forum › Problemi Vari con WP › Escludere categoria da homepage
-
AutorePost
-
-
12 Ottobre 2015 alle 17:50 #30194orsocapoPartecipante
Buonasera,
per escludere una o più categorie dalla HP ho inserito in function.php del tema child questo codice:
// Escludere categorie da home
function exclude_category($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-18’);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘exclude_category’);
Malgrado questo la categoria in questione continua a inserirsi lo stesso.
Grazie a tutti per l’aiuto
-
12 Ottobre 2015 alle 18:21 #118991nickPartecipante
Ciao, in attesa di pareri più esperti, vedo una differenza rispetto a questi riferimenti: https://codex.wordpress.org/Function_Reference/is_home
Prova a sostituire la riga che contiene la condizione:
if ( $query->is_home ) {
con:
if ( $query->is_home() ) {
-
12 Ottobre 2015 alle 18:55 #118992orsocapoPartecipante
…purtroppo non è cambiato niente.
Grazie lo stesso
-
13 Ottobre 2015 alle 7:21 #118993elmaniseroPartecipante
Prova con questo:
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('category__not_in', '18');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category'); -
13 Ottobre 2015 alle 7:54 #118995SteveAglAmministratore del forum
Perchè $query->is_home quando la funzione è is_home() ?
-
13 Ottobre 2015 alle 8:27 #118996elmaniseroPartecipante
La mia risposta riguardava solo la sostituzione di cat con category__not_in
comunque
function exclude_category($query) {
if ( $query->is_home() ) {
$query->set('category__not_in', '18');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category'); -
13 Ottobre 2015 alle 9:30 #118997SteveAglAmministratore del forum
La mia era una risposta in generale non diretta a te personalmente La funzione è is_home() probabilmente appaiono pure dei warning nei log.
-
13 Ottobre 2015 alle 10:52 #118999orsocapoPartecipante
ho provato a modificare il codice con l’ultimo suggerimento ma la categoria continua a comparire in home page.
Potrebbe essere il tema “Twenty Fourteen” che non accoglie la modifica? Ipotesi stramba ma le butto là¬
Grazie per la collaborazione
-
13 Ottobre 2015 alle 11:08 #119000TittiModeratore
Quel codice funziona perfettamente e funziona anche con twenty fourteen. I motivi possono esser diversi, dal banale copia-incolla con strane formattazioni mediante un rich-text editor invece che con notepad, a un plugin che interferisce – bisognerebbe sempre fare le prove richieste nel box per questo tipo di problemi prima di aprire il topic – da una cache persistente ad un child-theme non corretto…
Il problema è tuo localmente, ma non hai dato nessuna informazione.
-
13 Ottobre 2015 alle 11:21 #119001orsocapoPartecipante
Il child theme va bene perchè ci sono altre funzioni che funzionano perfettamente.
Il codice lo trasferisco dal blocco note.
Le prove lo ho fatte tutte, ecco perchè non riesco a capire e ho chiesto aiuto
Grazie
-
13 Ottobre 2015 alle 12:02 #119002TittiModeratore
Metti link alla homepage e dଠqual è la categoria che vuoi escludere.
-
13 Ottobre 2015 alle 12:12 #119003orsocapoPartecipante
la categoria è rassegnestampa
-
13 Ottobre 2015 alle 12:27 #119004TittiModeratore
Beh, non ho guardato tutte le 25 pagine, ma nelle prime 3 la categoria rassegnestampa non c’è… in quale pagina (link) non dovrebbe esserci e invece c’è?
-
13 Ottobre 2015 alle 12:32 #119005elmaniseroPartecipante
Per me sbagli id, prova con 27
-
13 Ottobre 2015 alle 12:34 #119006orsocapoPartecipante
l’articolo che non voglio che appaia in homepage l’ho tolto.
Posso rimetterlo cosଠsi vede in homepage
-
13 Ottobre 2015 alle 12:36 #119007elmaniseroPartecipante
Per me sbagli id, prova con 27
-
13 Ottobre 2015 alle 12:48 #119008orsocapoPartecipante
ho provato col 27…niente
comunque ora il post/categoria incriminata sta là¬
-
13 Ottobre 2015 alle 12:50 #119009elmaniseroPartecipante
Puoi mettere per un attimo i permalink di default cosଠvediamo di quale id si tratta?
-
13 Ottobre 2015 alle 12:58 #119010orsocapoPartecipante
perdonami, cosa si intende per permalink di default?
Questi?
Impostazioni comuni
Predefinito http://www.consequenze.org/?p=123
Data e nome http://www.consequenze.org/2015/10/13/articolo d’esempio/
Mese e nome http://www.consequenze.org/2015/10/articolo d’esempio/
Numerico http://www.consequenze.org/archives/123
Nome articolo http://www.consequenze.org/articolo d’esempio/
Struttura personalizzata http://www.consequenze.org
/%postname%/
-
13 Ottobre 2015 alle 12:58 #119011elmaniseroPartecipante
il primo
-
13 Ottobre 2015 alle 13:05 #119012orsocapoPartecipante
quello che ho impostato è il “nome articolo”
Nel caso dell’articolo in questione è http://www.consequenze.org/lazionauta-it-21092015/
-
13 Ottobre 2015 alle 13:09 #119013elmaniseroPartecipante
Quello che hai impostato lo vedo, ti chiedo per la terza volta di mettere per un attimo il permalink predefinito e salvare, cosଠvedo quale id è, poi rimetti il nome articolo.
-
13 Ottobre 2015 alle 13:13 #119014orsocapoPartecipante
fatto
-
13 Ottobre 2015 alle 13:15 #119015elmaniseroPartecipante
Ma hai una cache attiva allora perchè io non vedo nulla di cambiato ma tu che sei loggato la dovresti vedere al posto di http://www.consequenze.org/category/c16-articolirassegnestampa/ cosa c’è scritto?
-
13 Ottobre 2015 alle 13:16 #119016
-
13 Ottobre 2015 alle 13:17 #119017orsocapoPartecipante
beh…ho ricambiato il numero della categoria e ora pare vada bene.
Avevi ragione, l’ID della categoria era 27 (ma l’avevo messa anche prima…boh) ma nella lista appare come 18.
Grazie mille davvero per la pazienza e per la cortesia
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.