2017-11-16 5 views
0

外部ワードプレスブログのブログリストを表示するように働いています。 コードでPHPの問題があり、それが唯一の代わりにこれを試してみてください一つだけ外部Wordpressブログフィード表示

add_shortcode('first', 'foobar_func'); 

    function foobar_func($atts){ 

    $feed = fetch_feed('https://wordpress.org/news/feed/'); 

    if (!is_wp_error($feed)): 
     $maxitems = $feed->get_item_quantity(3); 
     $rss_items = $feed->get_items(CURL_HTTP_VERSION_1_0, $maxitems); 
    endif; 

    if ($maxitems == 0) { 
     return '<li>No items.</li>'; 
    } else foreach ($rss_items as $item) { 
     $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $item->get_content(), $matches); 
     $first_img = $matches [1][0]; 
     $testts = esc_html($item->get_title()); 
    } 
    return $testts; 
    } 
+0

基本的なデバッグを試しましたか? – ProEvilz

+0

はい、私はしました。何かが "foreach"に混乱しています – Eurasia

+0

なぜあなたは 'CURL_HTTP_VERSION_1_0'を持っていますか? 0と設定すると、ドキュメントのように – ProEvilz

答えて

0

を示しています。 が0のために交換されました。

add_shortcode('first', 'foobar_func'); 

    function foobar_func($atts){ 

    $feed = fetch_feed('https://wordpress.org/news/feed/'); 

    if (!is_wp_error($feed)): 
     $maxitems = $feed->get_item_quantity(3); 
     $rss_items = $feed->get_items(0, $maxitems); 
    endif; 

    if ($maxitems == 0) { 
     return '<li>No items.</li>'; 
    } else foreach ($rss_items as $item) { 
     $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $item->get_content(), $matches); 
     $first_img = $matches [1][0]; 
     $testts = esc_html($item->get_title()); 
    } 
    return $testts; 
    } 
+0

が動作していますが、1つしか出力されません。 $ maxitems = $ feed-> get_item_quantity(3); - それは3でなければなりません – Eurasia

+0

代わりに$ maxitemsを '5'に置き換えてみてください。 – ProEvilz

関連する問題