如何加上「;特色形象;谷歌警报xml

如何加上「;特色形象;谷歌警报xml,xml,google-alerts,Xml,Google Alerts,我正在使用Google Alerts RSS提要来填充我网站上的边栏小部件。它当前显示文章的链接和发布日期,但我还想在每个项目旁边显示缩略图。在阅读了关于这个问题的文章后,我发现问题在于Google Alerts XML中没有图像。是否有一种变通方法或代码可以从每个源项目(文章)中获取特色图像或缩略图,并将其显示在我的侧边栏中 我尝试了所有与向RSS提要添加图像相关的插件,结果都是负面的。我尝试了几个代码片段,结果都是否定的 这是一个无法工作的代码段: `add_action( 'rss2_it

我正在使用Google Alerts RSS提要来填充我网站上的边栏小部件。它当前显示文章的链接和发布日期,但我还想在每个项目旁边显示缩略图。在阅读了关于这个问题的文章后,我发现问题在于Google Alerts XML中没有图像。是否有一种变通方法或代码可以从每个源项目(文章)中获取特色图像或缩略图,并将其显示在我的侧边栏中

我尝试了所有与向RSS提要添加图像相关的插件,结果都是负面的。我尝试了几个代码片段,结果都是否定的

这是一个无法工作的代码段:

`add_action( 'rss2_item', 'add_post_featured_image_as_rss_item_enclosure' 
);
function add_post_featured_image_as_rss_item_enclosure() {
    if ( ! has_post_thumbnail() )
        return;
    $thumbnail_size = apply_filters( 'rss_enclosure_image_size', 
'thumbnail' );
    $thumbnail_id = get_post_thumbnail_id( get_the_ID() );
    $thumbnail = image_get_intermediate_size( $thumbnail_id, 
$thumbnail_size );
    if ( empty( $thumbnail ) )
        return;
    $upload_dir = wp_upload_dir();
    printf( 
        '<enclosure url="%s" length="%s" type="%s" />',
        $thumbnail['url'], 
        filesize( path_join( $upload_dir['basedir'], $thumbnail['path'] ) 
), 
        get_post_mime_type( $thumbnail_id ) 
    );
}
`add_action('rss2_item','add_post_特色_image_as_rss_item_enclosure'
);
函数add_upost_feature\u image_as_urss\u item\u enclosure(){
如果(!具有\u post\u缩略图())
返回;
$thumbnail\u size=apply\u过滤器('rss\u enclosure\u image\u size',
“缩略图”);
$thumbnail\u id=get\u post\u thumbnail\u id(get\u the\u id());
$thumbnail=image\u get\u mediate\u size($thumbnail\u id,
$U尺寸);
如果(空($缩略图))
返回;
$upload_dir=wp_upload_dir();
printf(
'',
$thumbnail['url'],
文件大小(path_join($upload_dir['basedir'],$thumbnail['path']))
), 
get_post_mime_类型($thumbnail_id)
);
}
所有尝试过的插件/代码片段都没有产生任何错误消息,只是什么也没做


尝试将以下代码复制到functions.php或自定义插件。这将在rss2提要(应该是yourdomain.com/feed/)中创建一个有效的附件标签,并带有指向全尺寸特色图像的链接

add_action( 'rss2_item', 'rss_feed_add_featured_image_enclosure' );
function rss_feed_add_featured_image_enclosure()
{

if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( get_the_ID() ) ) {
    $attachment_id = get_post_thumbnail_id(get_the_ID());
    $url = get_the_post_thumbnail_url(get_the_ID(),'full');
    $length = filesize(wp_get_original_image_path($attachment_id));
    $type = get_post_mime_type($attachment_id);
    echo '<enclosure url="' . $url . '" length="' . $length . '" type="' . $type . '" />
';}}
add_动作('rss2_项目'、'rss_提要'、'add_特色图像_附件');
功能rss_提要_添加_特色_图像_附件()
{
if(函数_存在('has_post_缩略图')&&has_post_缩略图(获取_ID())){
$attachment_id=get_post_缩略图_id(get_the_id());
$url=get_the_post_缩略图_url(get_the_ID(),'full');
$length=filesize(wp_get_original_image_path($attachment_id));
$type=get\u post\u mime\u type($attachment\u id);
回声'
';}}

尝试将以下代码复制到functions.php或自定义插件。这将在rss2提要(应该是yourdomain.com/feed/)中创建一个有效的附件标签,并带有指向全尺寸特色图像的链接

add_action( 'rss2_item', 'rss_feed_add_featured_image_enclosure' );
function rss_feed_add_featured_image_enclosure()
{

if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( get_the_ID() ) ) {
    $attachment_id = get_post_thumbnail_id(get_the_ID());
    $url = get_the_post_thumbnail_url(get_the_ID(),'full');
    $length = filesize(wp_get_original_image_path($attachment_id));
    $type = get_post_mime_type($attachment_id);
    echo '<enclosure url="' . $url . '" length="' . $length . '" type="' . $type . '" />
';}}
add_动作('rss2_项目'、'rss_提要'、'add_特色图像_附件');
功能rss_提要_添加_特色_图像_附件()
{
if(函数_存在('has_post_缩略图')&&has_post_缩略图(获取_ID())){
$attachment_id=get_post_缩略图_id(get_the_id());
$url=get_the_post_缩略图_url(get_the_ID(),'full');
$length=filesize(wp_get_original_image_path($attachment_id));
$type=get\u post\u mime\u type($attachment\u id);
回声'
';}}