Home › Forum › Plugin e temi di WP › Campo personalizzato con IF
-
AutorePost
-
-
17 Gennaio 2012 alle 11:33 #20367SmiaoPartecipante
So benissimo che quello che chiedo a più a che fare con il PHP, ma non riesco a trovare la sintassi giusta e a capire come indicare cosa fare.
io ho questo campo personalizzato nella pagina
<?php $pageimage = get_post_meta($post->ID, 'pageimage', true); ?>
<img alt="" src="<?php echo $pageimage; ?>">
vorrei fare il modo che nel caso il campo sia vuoto lui mi carica un ‘altra immagine.
Pensavo fosse facile ma no riesco a capire come piazzare un IF.
Grazie mille a chiunque può aiutarmi.
-
17 Gennaio 2012 alle 12:09 #91905SteveAglAmministratore del forum
<?php
$pageimage = get_post_meta($post->ID, ‘pageimage’, true);
if ( empty($pageimage) {
$pageimage = URL_IMMAGINE_ALTERNATIVA;
}
?>
-
17 Gennaio 2012 alle 12:33 #91906SmiaoPartecipante
Delle volte mi sento proprio impedito, l’ignoranza lo fa.
<?php
$pageimage = get_post_meta($post->ID, 'pageimage', true);
if ( empty($pageimage) {
$pageimage = http://www.somesay.it/wp-content/themes/somesay/images/immaginevuota.jpg;
}
?>sicuramente è un errore di grammatica, ma non mi funziona.
Grazie per la velocità nell’aiutarmi.
-
17 Gennaio 2012 alle 12:45 #91907TittiModeratore
Manca una )
if ( empty($pageimage) )
-
17 Gennaio 2012 alle 13:48 #91909SmiaoPartecipante
Grazie Titti, ma non ce la facci proprio.
`<?php
$pageimage = get_post_meta($post->ID, ‘pageimage’, true);
if ( empty($pageimage)) {
$pageimage = http://www.somesay.it/wp-content/themes/somesay/images/immaginevuota.jpg ;
}
?>`
non mi restituisce nessun valore.
-
17 Gennaio 2012 alle 14:01 #91910SteveAglAmministratore del forum
Metti la url fra apici
-
17 Gennaio 2012 alle 14:29 #91911SmiaoPartecipante
Lo so che passo per scemo ma avevo gia provato con gli apici
$pageimage = 'http://www.somesay.it/wp-content/themes/somesay/images/logo.png' ;
Scusate
-
18 Gennaio 2012 alle 13:20 #91946SmiaoPartecipante
Risolto, era un errore mio nella scelta del template della pagina.
Il codice riportato è giusto e perfettamente funzionante.
Grazie e scusate.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.