2011-12-21 65 views
0

有沒有一種方法可以將縮略圖圖片url添加到wordpress feed?如何添加一個圖像url作爲一個項目的孩子飼料?

我知道如何將縮略圖添加到the_content,但我需要rss提要來佈置另一個域的頁面。所以我只是想使用$ item-> get_title(),$ item-> get_description()和縮略圖像$ item-> get_image_url

在其他domain.com我使用以下(其他域.com也是WP安裝)

require('../../../site/wp-load.php'); 
include_once(ABSPATH . WPINC . '/feed.php'); 
$rss= fetch_feed('domain.com/feed/?post_type=recipes'); 
foreach($rss->get_items() as $item) { 

    echo $item->get_title().'<br/>'.$item->get_description(); 
    echo '<hr/>'; 

} 

有什麼建議嗎?

回答

1

如果你想在圖像URL(SRC)

,你必須先用get_post_thumbnail_id讓拇指ID,然後使用wp_get_attachment_image_src來獲取圖像的src

<?php 
$post_thumbnail_id = get_post_thumbnail_id($post_id); 
$image_src = wp_get_attachment_image_src($post_thumbnail_id , $size, $icon); 
?> 
+0

TX但是是我試過了。這是最常用於將圖像添加到rss-feed $ item-> descreption的函數。在我的情況下,我想,我想添加一個節點到simpliepie 例如。如果我理解正確WP使用某種simplepie格式的rss提要,但我沒有包含圖像,所以它似乎。我試過get_image_url(); – alex 2011-12-21 14:32:38

+0

好的,我會更新我的帖子。 – 2011-12-21 14:40:08

+0

啊好吧,我看到你要去哪裏,我有'$ image_src = wp_get_attachment_image_src($ post_thumbnail_id,'full')原始img src; '但仍然我沒有看到我怎麼可以把這個網址到'add_filter('the_content_feed','rss_post_thumbnail');函數rss_post_thumbnail($ content){global $ post; if(has_post_thumbnail($ post-> ID)) \t \t $ post_thumbnail_id = get_post_thumbnail_id($ post-> ID); \t \t $ image_src = wp_get_attachment_image_src($ post_thumbnail_id,'full'); //在rss feed中放置$ image_src [0]的位置? \t \t $ content ='

'。$ image_src [0]。'

'。$ content; return $ content; \t }' – alex 2011-12-22 10:27:10

相關問題