Creare uno shortcode per includere i feed RSS è un'operazione semplice in WordPress.
Aggiungete il seguente codice al file functions.php
:
function my_feed( $atts, $content = null ) {
extract( shortcode_atts( array(
'url' => '',
'limit' => '5'
), $atts ) );
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed( $url );
$html = '';
if ( !is_wp_error( $rss ) ) {
$maxitems = $rss->get_item_quantity( $limit );
$rss_items = $rss->get_items( 0, $maxitems );
$html = '<ul class="my-feed">';
foreach ( $rss_items as $item ) {
$html .= '<li><a href="' . esc_url( $item->get_permalink() ) . '">' . esc_html( $item->get_title() ) . '</a></li>';
}
$html .= '</ul>';
}
return $html;
}
add_shortcode( 'my-feed', 'my_feed' );
Quindi potete usare lo shortcode come [my-feed url="http://sito/feed"]
.