正在显示外部wordpress博客的博客列表。 代码中存在PHP问题,它只显示一个
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 :(得分:0)
试试这个。注意CURL_HTTP_VERSION_1_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;
}