Home › Forum › Problemi Vari con WP › Problema con query_posts
-
AutorePost
-
-
18 Marzo 2009 alle 15:45 #9843TedCPartecipante
Salve a tutti.
Sto realizzando un layout piuttosto complesso, ricco di query_posts in home page. La versione di WordPress è la 2.7.1. Lavoro al momento in locale.
Nella sidebar, in alto, ho piazzato un tab ui di jQuery con gli ultimi post appartenenti a due categorie (una vignetta e un video, in pratica). Funziona praticamente quasi tutto, tranne un piccolo particolare.
Il layout infatti cambia stile dalla home alle altre pagine – essendo la home a tre colonne e le altre pagine a due. Nel body, nell’header, nel container principale e nel footer ho messo una variabile
<?php if (is_home()) { $body = 'home'; }
else { $body = 'main'; }
?>
In questo modo posso gestire lo stile del "div".
Ora però notato che in homepage il footer invece di apparire coon la class="home-footer" appare con la class="main-footer". Il che significa che non mi riconosce più la home come tale. Smanettendo un po', togliendo e mettendo, ho capito che il problema è il codice del tab UI di cui parlavo sopra. In pratica mi riconosce la home come tale finché non incontra la query contenute in quel codice. Vi metto il codice copiato su pastebin. Se qualcuno ha suggerimenti su come risolvere gliene sarei grato.
Spero di essere stato chiaro perché quello che sto facendo è piuttosto complesso e non sono riuscito a esprimermi meglio.
-
18 Marzo 2009 alle 16:52 #63901SteveAglAmministratore del forum
senza guardare il codice direi che siccome il footer è un altro file di WP non si passa la variabile che imposti con la if… e quindi se la perde… nel footer per generare la classe giusta ripeti il test…
-
18 Marzo 2009 alle 17:01 #63902TedCPartecipante
Eh, errore mio che non l’ho scritto. La variabile è nel file header.php e footer.php (insomma, ovunque vada la class). Se tolgo il codice incollato su pastebin funziona. Al momento ho risolto con un query_string nel file footer.php, ma lଠmi dava il problema contrario: la variabile funzionava solo in home. Cosଠho dovuto ritoccare il css per ovviare. Il problema rimane, però.
-
18 Marzo 2009 alle 22:52 #63911andreaPartecipante
Spesso, dopo una chiamata a query_posts(), una successiva chiamata a is_home() restituisce false.
Ad esempio dopo una chiamata a
query_posts(‘cat=119&showposts=1’);
is_home() sarà falso mentre is_category(119) sarà vero.
Per aggirare il problema puoi realizzare una pagina ad hoc da impostare come front page, e in questo caso il test su is_home() non è più necessario.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.