Juste un petit bout de code

WRInaute discret
Bonsoir,

Ca fait longtemps que je n'ai plus touché au php et encore, à l'époque je maitrisais pas tellement.

Je vous sollicite encore pour que vous m'aidiez. Il s'agit en fait d'un truc tout simple, mais je ne sais plus comment le rédiger en php...

Code:
<?php $vids = get_post_meta($post->ID, 'vids', true); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="http://img.youtube.com/vi/<?php echo($vids) ?>/2.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
Donc, je voudrais que:

Si $vids existe, alors on affiche
Code:
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="http://img.youtube.com/vi/<?php echo($vids) ?>/2.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
Mais si $vids n'existe pas, alors on affiche une image que j'aurais choisit.

Je sais que ça se fait très bien, seulement je ne me souviens plus comment...

Merci beaucoup pour votre aide !
 
WRInaute discret
Ben je pensais plus à un truc du genre

if
Ca ça est vrai, alors on fait ça

else
On affiche ça
 
WRInaute accro
En fait $vids existe forcément. Par contre si get_post_meta ne renvoie rien, $vids sera une chaîne vide.

Donc :

Code:
if ($vids != "")
{

}
else
{

}
 
WRInaute discret
Code:
<?php
    if (isset($vids) && !empty($vids))
    {
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="http://img.youtube.com/vi/<?php echo($vids) ?>/2.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
    }
    else
    {
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="/host/logoddncut.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
    }
?>

Hum, qu'est-ce qu'il manque pour que ça marche ?
 
WRInaute accro
Ouvrir les variables php (et les fermer) au bon endroit :
Code:
<?php
    if (isset($vids) && !empty($vids))
    {
?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="http://img.youtube.com/vi/<?php echo($vids) ?>/2.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
<?php
    }
    else
    {
?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="/host/logoddncut.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>
<?php
    }
?>
 
WRInaute discret
Erf oui merci ^^'

Avec ce code, seul
Code:
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="/host/logoddncut.jpg" alt="<?php the_title(); ?>" width="130px" height="97px" /></a>

S'affiche, et pas la vignette youtube. Pourtant $vids existe là où il y a la vignette =/
 
Discussions similaires
Haut