Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress RSS列表添加特色图片链接_Wordpress_Rss - Fatal编程技术网

WordPress RSS列表添加特色图片链接

WordPress RSS列表添加特色图片链接,wordpress,rss,Wordpress,Rss,我想要wordpress帖子rss列表特色图片链接 例: 测试标题 测试说明 图像链接 我没有使用插件 谢谢这样就可以了。将其添加到functions.php文件: // add the namespace to the RSS opening element add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' ); function custom_prefix_add_media_namespace() { ech

我想要wordpress帖子rss列表特色图片链接

例:

测试标题
测试说明
图像链接
我没有使用插件


谢谢

这样就可以了。将其添加到
functions.php
文件:

// add the namespace to the RSS opening element

add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' );

function custom_prefix_add_media_namespace() {
    echo "xmlns:media="http://search.yahoo.com/mrss/"n";
}

// add the requisite tag where a thumbnail exists
add_action( 'rss2_item', 'custom_prefix_add_media_thumbnail' );

function custom_prefix_add_media_thumbnail() {
    global $post;
    if( has_post_thumbnail( $post->ID )) {
        $thumb_ID = get_post_thumbnail_id( $post->ID );
        $details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');
        if( is_array($details) ) {
            echo '<media:thumbnail url="' . $details[0] . '" width="' . $details[1] . '" height="' . $details[2] . '" />';
        }
    }
}
//将名称空间添加到RSS打开元素
添加操作('rss2_ns','custom_prefix_add_media_namespace');
函数自定义\前缀\添加\媒体\命名空间(){
echo“xmlns:media=”http://search.yahoo.com/mrss/“n”;
}
//在存在缩略图的位置添加必要的标记
添加操作(“rss2项目”、“自定义前缀”添加媒体缩略图”);
函数自定义\前缀\添加\媒体\缩略图(){
全球$员额;
如果(有帖子缩略图($post->ID)){
$thumb\u ID=get\u post\u缩略图\u ID($post->ID);
$details=wp_get_attachment_image_src($thumb_ID,'thumbnail');
if(is_数组($details)){
回声';
}
}
}
此外,添加此选项时,请确保通过转到“设置”>“永久链接”重置永久链接(刷新它们),然后将永久链接更改为默认值,然后返回到定义的设置,或者只是重新保存

之后,检查你的订阅源,媒体应该在那里

// add the namespace to the RSS opening element

add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' );

function custom_prefix_add_media_namespace() {
    echo "xmlns:media="http://search.yahoo.com/mrss/"n";
}

// add the requisite tag where a thumbnail exists
add_action( 'rss2_item', 'custom_prefix_add_media_thumbnail' );

function custom_prefix_add_media_thumbnail() {
    global $post;
    if( has_post_thumbnail( $post->ID )) {
        $thumb_ID = get_post_thumbnail_id( $post->ID );
        $details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');
        if( is_array($details) ) {
            echo '<media:thumbnail url="' . $details[0] . '" width="' . $details[1] . '" height="' . $details[2] . '" />';
        }
    }
}