Home › Forum › Problemi Vari con WP › Campi personalizzati e if else
-
AutorePost
-
-
10 Luglio 2008 alle 11:52 #7229TheSneezerPartecipante
ciao a utti,
ho un problema con l’utilizzo dei campi personalizzati.
Ho creato un campo personalizzato “sottotitolo” da utilizzare nelle pagine dei post usando qesto codice:
<h2><?php echo get_post_meta($post->ID, "sottotitolo", true); ?></h2>
e viene visualizzato correttamente.
Il problema è che, avendo inserito il codice nella pagina header.php, nella index, nelle categorie e nelle pagine degli archivi, delle ricerche e dei tag, mi compare il testo del campo personalizzato del post più recente.
Ho provato quindi ad utilizzare l'if/else per risolvere il problema:
<?php /* se è un post */ if (is_post()) { ?> <h2><?php echo get_post_meta($post->ID, "sottotitolo", true); ?></h2>
<?php /* se è un archivio */ } elseif (is_month()) { ?> <h2>Sottotitolo Archivio <?php the_time('F Y'); ?></h2>
<?php /* se è un tag */ } elseif (is_tag()) { ?> <h2>Sottotitolo Tag</h2>
<?php /* se è la index */ } elseif (is_index()) { ?> <h2>Sottotitolo Index</h2>
<?php /* se è una ricerca */ } elseif (is_search()) { ?> <h2>Sottotitolo Ricerca</h2>
<?php } ?>
ma non funziona!!
Qualcuno sa dirmi dov'è l'errore?
-
10 Luglio 2008 alle 17:07 #55699ArturoPartecipante
allora ci sono piu’ modi o fare una cascata di if ed elseif in questo modo:
<?php if (is_home()) {
… quello che vuoi nella home…;
} elseif (is_search()) {
… nel search…;
} elseif (is_single()) {
… nell’articolo singolo…;
} elseif (is_page()) {
… nella pagina…;
} elseif (is_category()) {
… categorie…;
} elseif (is_archive()) {
… categorie…;
} elseif (is_month()) {
… mese…;
}
?>
oppure se vuoi semplificarti la vita, io preferisco farlo per ognuno cosi’:
<?php if (is_home()) { ?> quello che vuoi che appaia <?php } ?>
naturalmente copi n volte il tutto e cambi is_home() con la parte is_page, is_archive ecc.
-
10 Luglio 2008 alle 17:08 #55701ArturoPartecipante
ah, l’errore tuo era nel fatto che non chiudevi la graffa ad ogni apertura, o fai gli if e gli elseif oppure chiudi e riapri ogni volta la funzione.
-
10 Luglio 2008 alle 21:12 #55707TheSneezerPartecipante
Grazie mille Arturo!
Ora funziona tutto …
Ciao
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.