2016-08-17 7 views
0

以下のコードは、自分のwordpress RSSフィードに画像を追加します。私はイメージを自動的に対応する投稿にハイパーリンクさせるようにしたいと思っています。コードは、私のテーマののfunctions.phpであるWPパーマリンクをPHPに追加する

function wcs_post_thumbnails_in_feeds($content) { 
    global $post; 
    if(has_post_thumbnail($post->ID)) { 
     $content = get_the_post_thumbnail($post->ID) . '<span class="text">' . $content . '</span>'; 
    } 
    return $content; 
} 
add_filter('the_excerpt_rss', 'wcs_post_thumbnails_in_feeds'); 
add_filter('the_content_feed', 'wcs_post_thumbnails_in_feeds'); 
Can I change this so that the post_thumbnail is automatically wrapped with a link to the post? 

どのように私はget_the_post_thumbnail($ポスト> ID)リンクを使用してコードの一部を折り返すことができますか?ありがとう

答えて

0

get_permalink関数を使用して、投稿IDを渡すことができます。

function wcs_post_thumbnails_in_feeds($content) { 
     global $post; 
     if(has_post_thumbnail($post->ID)) { 
      $content = '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID) . '</a><span class="text">' . $content . '</span>'; 
     } 
     return $content; 
    } 
+0

ありがとうございます@ Fencer04 - それは完璧に動作します! :-) – jkendall

関連する問題