Hay ocasiones en las que desea mostrar una fuente RSS externa en su blog. Quizás un feed de blog de su otro blog o algún otro sitio. Bueno, no necesitas un plugin para hacer esto porque WordPress tiene una función incorporada que se encargará de esto. En este artículo, le mostraremos cómo puede mostrar una fuente RSS externa en su blog. De esta manera, incluso puede usar WordPress como un agregador de noticias.
Simplemente pegue el siguiente código en cualquier archivo de WordPress que elija. Preferiblemente en una página personalizada que usted cree.
<h2><?php _e( 'Recent news from Some-Other Blog:', 'my-text-domain' ); ?></h2> <?php // Get RSS Feed(s) include_once( ABSPATH . WPINC . '/feed.php' ); // Get a SimplePie feed object from the specified feed source. $rss = fetch_feed( 'https://www.wpbeginner.com/feed/' ); if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly // Figure out how many total items there are, but limit it to 5. $maxitems = $rss->get_item_quantity( 5 ); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items( 0, $maxitems ); endif; ?> <ul> <?php if ( $maxitems == 0 ) : ?> <li><?php _e( 'No items', 'my-text-domain' ); ?></li> <?php else : ?> <?php // Loop through each feed item and display each item as a hyperlink. ?> <?php foreach ( $rss_items as $item ) : ?> <li> <a href="<?php echo esc_url( $item->get_permalink() ); ?>" title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>"> <?php echo esc_html( $item->get_title() ); ?> </a> </li> <?php endforeach; ?> <?php endif; ?> </ul>
Asegúrese de cambiar la URL de los feeds y la cantidad y cualquier otra configuración que desee.
Fuente: Códice de WordPress
.
Fuente: wpbeginner