• 11-02-2013, 00:04:51
    #1
    Nasıl bir başlık atabilirim bilemedim.

    Sorun şu arkadaşlar. WordPress ile içerikteki resmi alıyorum. Eğer resim varsa resmi yoksa default atadığım resmi gösteriyor.

    Fakat şöyle kod girilen yerde if koşunu giremedim.
    				$id =$search->ID;
        $the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
        $pattern = '!<img.*?src="(.*?)"!';
        preg_match_all($pattern, $the_content, $matches);
        $image_src = $matches['1'][0];
                    $content.= '<li><a title="'.$title.'" href="'.get_permalink($search->ID).'"><img src="'.$image_src.'" alt="'.$title.'" title="'.$title.'" width="140" height="100" /><b>'.$title.'</b></a></li>';
    bu koda aşağıdaki nasıl ilave ederim.

    if ( empty($image_src) ) {
        echo 'http://www.siteadi.com/wp-content/themes/tema/images/thumbnail.jpg';
    } else {
        echo ''.$image_src.'';
    }
  • 11-02-2013, 00:09:34
    #2
    Şu satırı:

    $image_src = $matches['1'][0];
    Şöyle değiştirdiğin takdirde olması gerek:

    $image_src = empty($matches['1'][0]) ? 'http://resminyolu' : $matches[1][0];
  • 11-02-2013, 00:11:26
    #3
    bayGaReZ adlı üyeden alıntı: mesajı görüntüle
    Şu satırı:

    $image_src = $matches['1'][0];
    Şöyle değiştirdiğin takdirde olması gerek:

    $image_src = empty($matches['1'][0]) ? 'http://resminyolu' : $matches[1][0];
    çok teşekkür ederim çalıştı.