1

I am using a RSS feeds widget on my dashboard as shown in this Q&A. Problem is feeds doesn't show up any visual like images or videos. I verified this by looking raw feeds which I used. Here is a snapshot of my feed dashboard widget:
image.

How can I get visuals or is this the way WordPress shows data?

1
  • Taylor, try to research this site for building a Question, this way the answerer only spends time on the solution and not in the research. As you can see, I built the Answer with bits already existent here in WordPress Development ;)
    – brasofilo
    Commented Mar 16, 2013 at 14:52

1 Answer 1

0

I couldn't manage to make wp_widget_rss_output to show the content without stripping HTML tags. Reference Q&A's:

But, using the function fetch_feed we can grab the full feed contents. Check also the SimplePie function reference. See comments for details:

<?php
/**
 * Plugin Name: RSS Dashboard Widget with Images
 * Version: 1.0
 * Description: Display an array of feeds in a dashboard widgets displaying full content without stripping any HTML tags
 * Author: Rodolfo Buaiz
 * Author URI: https://wordpress.stackexchange.com/users/12615/brasofilo
 * Plugin URI: https://wordpress.stackexchange.com/q/91137/12615
 *
 * License: GPLv2 or later
 */

add_action( 'wp_dashboard_setup', 'multiple_feeds_wpse_91137' );

function multiple_feeds_wpse_91137() 
{
     wp_add_dashboard_widget( 
        'dashboard_custom_feed', 
        'Latest News', 
        'dashboard_feed_output_wpse_91137' 
    );
}

function dashboard_feed_output_wpse_91137() 
{
    // Array with Title => Address
    $feeds = array( 
        'CBC Canada'     => 'http://rss.cbc.ca/lineup/topstories.xml',
        'Valencia Spain' => 'feed://www.levante-emv.com/elementosInt/rss/39', 
        'WP Engineer'    => 'http://wpengineer.com/feed/',
    );

    // Set max-height and enable scrolling
    echo '<div class="rss-widget" style="max-height:300px;overflow-y:auto">';

    // Iterate through feed
    foreach( $feeds as $title => $url )
    {
        echo "<h3>$title</h3>";

        // Fetch feed
        $rss = fetch_feed( $url );

        // Check for errors
        if ( is_wp_error( $rss ) )
        {
            echo "error fetching: $title";
        }
        else
        {
            // Process feed items using SimplePie methods
            $maxitems = $rss->get_item_quantity(4);
            $rss_items = $rss->get_items(0, $maxitems); 

            // Nothing in the feed
            if ($maxitems == 0) 
            {
                echo 'No items.';
            } 
            // Iterate through feed items
            else 
            {
                echo '<ul>';
                foreach ( $rss_items as $item ) 
                { 
                    // Prepare contents
                    $link = $item->get_permalink();
                    $title = $item->get_title();
                    $date = $item->get_date();
                    $content = $item->get_content();
                    // Display content
                    echo "<li><a href='$link'>$title</a> : <small>$date</small><br />$content</li>"; 
                }
                echo '</ul>';
            }
        }       
    }
    echo "</div>";
}

Reference Q&A's:

2
  • learnt alot,, especially from these references you provided. Thanks Braso! Code works smoothly,I have heard about simple pie and also about yahoo pipes, but never intended to use. Now I will modify further using these.
    – 10wtaylor
    Commented Mar 16, 2013 at 18:04
  • Well, I learned a lot too with this one, ain't this place cool?! ;)
    – brasofilo
    Commented Mar 16, 2013 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.