Konu ile ilgili yardımcı olan/olmaya çalışan arkadaşlara şimdiden teşekkür ederim.Bahsettiğim konu resim içerisinde olan dikdörtgen içine aldığım kısımdır.
13
●2.242
<div style="display:none;" itemscope itemtype="http://data-vocabulary.org/Recipe" > <h1 itemprop="name">Title wpiçin kod</h1> <img itemprop="photo" src="resim yolu" /> <span itemprop="review" itemscope itemtype="http://data-vocabulary.org/Review-aggregate"> <span itemprop="rating">5</span> <span itemprop="count">41</span></span> </div>
<div style="display:none;" itemscope itemtype="http://data-vocabulary.org/Recipe" > <h1 itemprop="name"><?php the_title(); ?></h1> <img itemprop="photo" src="<?php echo resimgoster() ?>" /> <span itemprop="review" itemscope itemtype="http://data-vocabulary.org/Review-aggregate"> <span itemprop="rating"><?php $rastgel = rand(1,5); echo $rastgel; ?></span> <span itemprop="count"><?php $rastgel = rand(12,59); echo $rastgel; ?></span></span> </div>function.php'nin içine de şu kodu uygun bir yere koyun.
function resimgoster() {
global $post, $posts;
$resimbir = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$resimbir = $matches [1] [0];
if(empty($resimbir)){
$resimbir = "http://localhost//wp-content/themes/son/resim/resim-yok.gif";
}not: resimbir yolunu kendinize göre düznelersiniz. kolay gelsin.
<div style="display:none;" itemscope itemtype="http://data-vocabulary.org/Recipe" >
<h1 itemprop="name"><?php the_title(); ?></h1>
<img itemprop="photo" src="<?php
$metaresim = get_post_meta($post->ID, "resim", true);
if(empty($metaresim)){
echo 'http://www.site.com/yildiz.jpg';
}else{
echo $metaresim;
}
?>" />
<span itemprop="review" itemscope itemtype="http://data-vocabulary.org/Review-aggregate">
<span itemprop="rating"><?php echo rand(2, 8); ?></span>
<span itemprop="count"><?php echo rand(1, 55); ?></span></span>
</div>Bence bu daha kolay. Özel alandan resim anahtarı ile eklediğiniz resmi gösterir. Eğer bir resim tanımlamadıysanız site.com/yildiz.jpg resmini gösterir.