Bunu soran çok oluyordu cevaben yazmak istedim, umarım başlangıç seveysinde olan arkadaşlar ve hızlı çözüm arayanlar için faydalı olur.
WordPress Rss feed lerde yazı içerisindeki ilk resmin hem enclosure(http://www.xs4all.nl/~foz/mod_enclosure.html) hem media:thumbnail(http://search.yahoo.com/mrss/) hem de RSS leri expert/özet olarak(/wp-admin/options-reading.php) yayınlıyorsanız ilk resmin Feed de görünmesini sağlamak için aşağıda benim hazırladığım fonksiyonu kullanabilirsiniz. Ayrıca benim hazırladığım fonksiyonda expert/özet yayınlarda devamını oku bağlantısı da bulunmakta.
Yapacağınız şey WordPress temanızın içerisinde bulunan function.php dosyası içerisine aşağıdaki kodları eklemek. Temanızda function.php dosyası yoksa kodları wp-config.php dosyasına uygun bir yere yazabilir veya hazırladığım şu eklentiyi indirip kullanabilirsiniz (plugin manueldir kontrol paneli yok yani kaynaktan düzenlemeniz gerekir), kısa yoldan plugin de /i/ klasörü içindeki wolkanca.gif dosyasını başka resimle değiştirirseniz varsayılan resim o olmuş olur.
//yazının ilk resmini almak için function
function yaziresim(){ //yazının ilk resmini çekiyorum
global $post, $posts;
$yaziresim = ''; ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches)
|| preg_match_all('/<object[0-9 a-z_?*=\":\-\/\.#\,<>\\n\\r\\t]+<\/object>/smi', $post->post_content, $matches);
$yaziresim = $matches [1] [0];
if(empty($yaziresim)){ //yazıda video varsa onun resmini çekiyorum
$mediaSearch = preg_match_all('#http://wolkanca\.com/wp-content/uploads/i/v/([^&"\'? ]*)\.flv#', $post->post_content, $matches2);
$first_media = $matches2 [1] [0];
$yaziresim = "https://wolkanca.com/eski/wp-content/uploads/i/wolkanca.gif";
}
if(!empty($yaziresim)){ //yazıda resim varsa
$result = $yaziresim;
}
if(!empty($first_media)){ //yazıda resim yoksa varsayılan resim
$result = "https://wolkanca.com/eski/wp-content/uploads/i/wolkanca.gif";
}
return $result;
}
//feed ve diğer site içi the_excerpt_rss lere eklemek için function
function insertyaziresim($content){
if(is_feed()){ // Rss feedler için
$content = '<img alt="'.get_the_title_rss().'" src="'.yaziresim().'" style="display:inline;float:left;margin-right:15px;"
class="alignleft" align="left" hspace="5" width="90" height="90" />'
. $content .
'<br style="clear:both;" /> <a href="'.get_permalink().'" title="'.get_the_title_rss().'">Devamını okuyun →</a>' ;
} else { //Diğer the_excerpt_rss ler için
$content = '<a href="'.get_permalink().'" title="'.get_the_title_rss().'"><img alt="'.get_the_title_rss().'"
src="'.yaziresim().'" width="90" height="90" class="alignleft" /></a>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'insertyaziresim'); //the_excerpt_rss ekle
add_filter('the_content_feed', 'insertyaziresim'); //the_content_feed ekle
function insertyaziresim_rss(){ //Rss feedler için enclosure ve media:thumbnail
if(is_feed()){
echo '<enclosure url="'.yaziresim().'" length="0" type="image/jpeg" /> <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="'.yaziresim().'" height="90" width="90" />';
}
}
add_action('rss_item', 'insertyaziresim_rss'); //rss_item ekle
add_action('rss2_item', 'insertyaziresim_rss'); //rss2_item ekle
add_action('atom_entry', 'insertyaziresim_rss'); //atom_entry ekle
Afiyet olsun.
“WordPress Rss e kolayca resim, media:thumbnail ve enclosure eklemek” için 6 yanıt
teşekkürler bilgi için.
selam ,
daha önce bu ekletiyi kullanmıştım. sıkıntı yoktu ancak wordpress son versionunu güncelleme yaptıktan sonra bu eklenti çalışmadı. 36 cı kolonda hata tespit ediyo. esasen orda sadece “}” bu işaret var. eklentinin güncellemesini aparsanız sevinirim teşekkürler…
inan kodda hata vardır değişmiş olabilir ben yeniden aşağıya yazayım:
function yaziresim(){
global $post, $posts; $yaziresim = ''; ob_start(); ob_end_clean(); $output =
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content,
$matches) || preg_match_all('/<object[0-9
a-z_?*=\":\-\/\.#\,<>\\n\\r\\t]+<\/object>/smi', $post->post_content, $matches);
$yaziresim = $matches [1] [0];
if(empty($yaziresim)){
$mediasearch = preg_match_all('#/wp-content/uploads/i/v2/([^&"\'? ]*)\.flv#',
$post->post_content, $matches2); $first_media = $matches2 [1] [0]; $yaziresim =
get_bloginfo ('siteurl'😉."/varsayilanresim.jpg";
}
if(!empty($yaziresim)){
$result = $yaziresim;
}
if(!empty($first_media)){
$result = get_bloginfo ('siteurl'😉."/varsayilanresim.jpg";
}
return $result;
}
function insertyaziresim($content){
if(is_feed()){
$content = '<a href="'.get_permalink().'" title="'.get_the_title_rss().'"><img
alt="'.get_the_title_rss().'" src="'.yaziresim().'"
style="display:inline;float:left;margin-right:15px;width:120px;height:90px;"
class="alignleft" align="left" hspace="5" width="120" height="90" /></a>' .
$content . '<br style="clear:both;" /> <a href="'.get_permalink().'"
title="'.get_the_title_rss().'">devamını okuyun →</a> <hr />';
} else {
$content = '<a href="'.get_permalink().'" title="'.get_the_title_rss().'"><img
alt="'.get_the_title_rss().'" src="'.yaziresim().'" width="100" height="90"
class="alignleft" /></a>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'insertyaziresim'😉;
add_filter('the_content_feed', 'insertyaziresim'😉;
function insertyaziresim_rss(){
if(is_feed()){
echo '<enclosure url="'.yaziresim().'" length="0" type="image/jpeg" />
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/"
url="'.yaziresim().'" width="120" height="90" />';
}
}
add_action('rss_item', 'insertyaziresim_rss', 10, 2 );
add_action('rss2_item', 'insertyaziresim_rss', 10, 2 );
add_action('atom_entry', 'insertyaziresim_rss', 10, 2 );
hocam emeklerine sağlık bir deneyelim bakalım başarılı olabilecekmiyiz.
bu konu hakkında bir sorun olursa buradan sorabilirsin abdullah.
yorumun için teşekkür ederim.
hay allah razı olsun.. 1 haftadır denemediğim yol kalmadı.. en son bunu denedim oldu..