php – 如何使用SimplePie从wordpress RSS获取自定义数据

我在wordpress中对RSS提要进行了一些更改,我正在使用fetch_Feed()向另一个网站显示数据.
想象一下,有两个名为#wordpress1和#wordpress2的网站.
这是我添加到#wordpress1的functions.PHP文件中的代码

add_action('RSS2_item', 'dw_add_data_to_RSS');
function dw_add_data_to_RSS(){
    global $post;

    if( $post->post_type == 'product' ) {
        $product = new WC_Product( $post->ID );

        $output = '';
        $thumbnail_ID = get_post_thumbnail_id( $post->ID );
        $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail');
        $output  = '<post-thumbnail>';
        $output .= '<url>'. $thumbnail[0] .'</url>';
        $output .= '<width>'. $thumbnail[1] .'</width>';
        $output .= '<height>'. $thumbnail[2] .'</height>';
        $output .= '</post-thumbnail>';

        $output .= '<price>' . number_format( $product->get_price() ) . ' ' . get_woocommerce_currency_symbol() . '</price>';

        echo $output;
    }
}

代码将产品价格和缩略图添加RSS Feed现在我们需要在#wordpress2上显示这些数据,但我不知道该怎么做

$RSS = fetch_Feed( 'http://localhost/wp/Feed/?post_type=product' );
if ( ! is_wp_error( $RSS ) ) {
    $maxitems  = $RSS->get_item_quantity( 10 ); 
    $RSS_items = $RSS->get_items( 0, $maxitems );
}

foreach ( $RSS_items as $item ) {
    echo '<a href="'. $item->get_permalink() .'"><img src="{MY_IMAGE_FROM_RSS}"> <span class="price">{MY_PRICE_FROM_RSS}</span></a>';
}

在上面的代码中我应该使用什么而不是MY_IMAGE_FROM_RSS和MY_PRICE_FROM_RSS

解决方法:

您应该使用get_item_tags()函数并使用空白作为所需的命名空间.

对于MY_IMAGE_FROM_RSS,请使用$item-> get_item_tags(”,’post-thumbnail’)[0] [‘child’] [”] [‘url’] [0] [‘data’]和MY_PRICE_FROM_RSS使用$item – &GT get_item_tags( ”, ‘价格’)[0] [ ‘数据’]

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...