我成功地使用fetch\\u feed()在仪表板小部件中显示RSS提要。但是,我无法从提要中的项目加载缩略图。我正试图用get\\u image\\u url()方法来实现这一点,但是,WordPress将该方法错误为未定义的方法。
代码如下。。。
function example_dashboard_widget_function() {
// Display whatever it is you want to show
$rss = fetch_feed( "http://localhost/testsite/wp-content/test.rss" );
if ( is_wp_error($rss) ) {
if ( is_admin() || current_user_can(\'manage_options\') ) {
echo \'<p>\';
printf(__(\'<strong>RSS Error</strong>: %s\'), $rss->get_error_message());
echo \'</p>\';
}
return;
}
if ( !$rss->get_item_quantity() ) {
echo \'<p>No RSS items to show!</p>\';
$rss->__destruct();
unset($rss);
return;
}
echo "<ul>\\n";
if ( !isset($items) )
$items = 10;
foreach ( $rss->get_items(0, $items) as $item ) {
$publisher = \'\';
$site_link = \'\';
$link = \'\';
$content = \'\';
$date = \'\';
$image = \'\';
$image = $item->get_image_url();
// $image = esc_url( strip_tags( $item->get_thumbnail() ) );
$link = esc_url( strip_tags( $item->get_link() ) );
$content = $item->get_content();
$content = wp_html_excerpt($content, 250) . \' ...\';
echo "<li><img src=\'$image\' /><a href=\'$link\'>$link</a> - $content</li>\\n";
}
echo "</ul>\\n";
$rss->__destruct();
unset($rss);
}