Home › Forum › Problemi Vari con WP › Kubrick, template e if ( !$withcomments && !is_single() ) {
-
AutorePost
-
-
23 Agosto 2007 alle 11:47 #4403oruxPartecipante
Ho bisogno di aiuto, perfavore!
Modificando il tema kubrick, ho aggiunto un template di pagina senza sidebar.
Il problema nasce dal fatto che il fondo continua a essere kubrickbg.jpg anche se la pagina è widecolumn.
Dipende tutto da questo codice che si trova in header (credo), ma non so come modificarlo, non conoscendo php (vado a intuito).
Soprattutto non capisco cosa significa “if ( !$withcomments && !is_single() ) {“
Ecco il codice da modificare.
<style type="text/css" media="screen">
<?php
// Checks to see whether it needs a sidebar or not
if ( !$withcomments && !is_single() ) {
?>
#page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg.jpg") repeat-y top; border: none; }
<?php } else { // No sidebar ?>
#page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbgwide.jpg") repeat-y top; border: none; }
<?php } ?>
</style>
-
23 Agosto 2007 alle 16:06 #46290oruxPartecipante
Ho capito una cosa.
La chiave sta in
if ( !$withcomments && !is_single() ) {
intanto $withcomments è semplicemente una variabile che viene impostata in questo momento e non in un altro, per cui può essere rinominata in qualsiasi modo senza cambiare il risultato.
Il significato del codice è:
Se la pagina che si visualizza (che chiamiamo $withcomments anche se era meglio chiamarla in un altro modo… per esempio $withsidebar) è single
allora usa come sfondo kubrickbg.jpg
altrimenti usa come sfondo kubrickbgwide.jpg
ORA
Io ho creato un template di pagina con un file che si chiama page_lab.php. Ho assegnato al template il nome di “Laboratorio”.
Vorrei modificare questo
if ( !$withcomments && !is_single() ) {
in qualcosa tipo
if ( !$withsidebar && !is_single() && !is_IL_MIO_TEMPLATE_LABORATORIO() ) {
Come faccio a scrivere !is_IL_MIO_TEMPLATE_LABORATORIO() ?
Esiste un tag condizionale per i template?
-
23 Agosto 2007 alle 21:17 #46303ondapiPartecipante
ti suggerisco un’altra strada
hai creato un nuovo template di pagina, sotto l’intestazione del template
c’e una riga che richiama l’header.php
<?php get_header(); ?>
che praticamente non fa altro che dire prendi il contenuto dell’header e mettilo qua dentro
ora il contenuto dell’header è lo stesso per tutte le pagine, index search pagina archivi …
il consiglio che ti do è quello di sostituire quella riga di codice con l’intero contenuto dell’header.php
e poi modificarlo a tuo piacimento, in questa maniera le modifiche del’header del template non andranno ad influire sugli altri file
spero di essere stato chiaro
forse la soluzione da te suggerita di utilizzare if è magari più elegante ma mi sembra che rendere ogni singolo file autonomo dia meno problemi in caso di personalizzazione
-
23 Agosto 2007 alle 22:49 #46306oruxPartecipante
Grazie Ondapi!
Potrebbe essere una scappatoia, però c’è il problema che in header.php ci sono anche molte informazioni meta che potrei voler aggiornare manualmente ogni tanto.
“Moltiplicare” per cosଠdire gli header mi costringerebbe ogni volta ad aggiornare più di un file e se volessi creare più di un template diventerebbe ancora più fastidioso.
Ho un’altra scappatoia che non mi soddisfa pienamente (la tua è molto meglio e quasi quasi la adotto). Siccome il template che ho creato si applica alle pagine statiche potrei sostituire la solita riga con:
if ( !$withsidebar && !is_single() && !is_page(LISTA_ID_O_NOMI_DI_OGNI_PAGINA_A_CUI_SI_APPLICA_IL_TEMPLATE) ) {
Mi chiedo però (in mancanza di un tag condizionale specifico) se si possa creare una nuova funtion da chiamare is_template_nome() simile ai tag condizionali is_single(), is_page(), ecc. per modificare come avrei voluto:
if ( !$withsidebar && !is_single() && !is_template_nome() ) {
Sapete in quale file di wordpress sono definiti i tag condizionali: magari si può copiare un po’ di codice da là¬.
Comunque spero in altri suggerimenti Grazie mille!
-
24 Agosto 2007 alle 0:02 #46307ondapiPartecipante
si in effetti se metti mano spesso al tema ti trovi con alcuni doppioni
ma potresti anche sfruttare l’occasione per modificare il css di un singolo template creando una pagina completamente diversa dal resto del blog
per i tag condizionali non saprei proprio darti una mano, ti conviene, a meno chè l’aiuto non te lo suggerisca qualcun altro leggere qualcosa nel wiki e poi fare delle prove in locale
-
28 Agosto 2007 alle 22:36 #46383oruxPartecipante
Ho detto qualche cavolata nel post precedente cosଠtento di correggermi.
Il “!” è una negazione cosଠil significato del codice dovrebbe essere:
Se la pagina che si visualizza non è $withcomments e non è single
allora usa come sfondo kubrickbg.jpg
altrimenti usa come sfondo kubrickbgwide.jpg
PURTROPPO NON RIESCO A RISOLVERE IN MODO PULITO
La variabile &withcomments non compare altrove (penso) e sembra inutile. Il codice può essere riscritto infatti
if ( !is_single() ) {
oppure
if ( is_single() ) {
invertendo le immagini di background.LA SOLUZIONE TAMPONE (oltre a quella di Ondapi, che forse è l’unica funzionale)
andrebbe scritta:
if ( !is_single() || !is_page(ID_PAGINE_a_cui _si_applica_il_template) ) {
oppure
if ( is_single() || is_page(ID_PAGINE_a_cui _si_applica_il_template) ) {
invertendo le immagini di background.L’ID_PAGINA è assolutamente necessario: ne serve almeno uno. Il campo non può restare vuoto, altrimenti valuterebbe tutte le pagine page che hanno la sidebar sbagliando l’immagine di sfondo.
Possibile che nessuno mi sa dare la soluzione?
Dove sono finiti i guru?
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.