Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using this snip of code to get rss feed on my dashboard as widget. It becomes problematic when it displays 5-6 different rss feeds which makes me run down deep.

How can I add 6 different feeds in a single dashboard widget with scroll bar?

Thanks

    add_action('wp_dashboard_setup', 'my_dashboard_widgets');
function my_dashboard_widgets() {
     global $wp_meta_boxes;
     // remove unnecessary widgets
     // var_dump( $wp_meta_boxes['dashboard'] ); // use to get all the widget IDs
     unset(
          $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'],
          $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'],
          $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']
     );
     // add a custom dashboard widget
     wp_add_dashboard_widget( 'dashboard_custom_feed', 'Latest News', 'dashboard_custom_feed_output' ); //add new RSS feed output
}
function dashboard_custom_feed_output() {
     echo '<div class="rss-widget">';
     wp_widget_rss_output(array(
          'url' => 'http://www.nytimes.com/feed',  //put your feed URL here
          'items' => 4, //how many posts to show
          'show_summary' => 1
     ));
     echo "</div>";
}
share|improve this question
2  
'url' should work with an array of multiple URLs. Have you tried that? –  toscho Mar 15 '13 at 13:54
    
Oops, I forgot,. Thanks Toscho for reminding! –  10wtaylor Mar 15 '13 at 14:52

2 Answers 2

up vote 2 down vote accepted

Yes, @toscho is right, the url works with an array of feeds adresses. And if you have 5/6 feeds, the total of items should be 20/24.

For clear separation, I think it's better to run the wp_widget_rss_output function n number of times, and prepare a previous array with titles and addresses and iterate through it. The scroll issue is just a matter of CSS.

add_action( 'wp_dashboard_setup', 'multiple_feeds_wpse_91027' );

function multiple_feeds_wpse_91027() 
{
     wp_add_dashboard_widget( 
        'dashboard_custom_feed', 
        'Latest News', 
        'dashboard_feed_output_wpse_91027' 
    );
}

function dashboard_feed_output_wpse_91027() 
{
    // Array with Title => Address
    $feeds = array( 
        'First Feed' => 'http://example.com/feed',
        'Second Feed' => 'http://example2.com/rss', 
        'Third Feed' => 'http://example3.com/feed/',
    );
    // Set max-height and enable scrolling
    echo '<div style="max-height:300px;overflow-y:auto">';
    foreach( $feeds as $key => $value )
    {
        echo "<h3>$key</h3>";
        wp_widget_rss_output(array(
              'url' => $value,
              'items' => 4, 
              'show_summary' => 1
         ));
    }
    echo "</div>";
}
share|improve this answer
1  
+1 for the suggestion of separating the feeds - it will look much better. –  David Gard Mar 15 '13 at 14:13
    
Thanks Brasofilo, works like charm! I was wondering if it could fetch data asynchronously itself every hour for updation. –  10wtaylor Mar 15 '13 at 19:42
    
@10wtaylor, use the filter wp_feed_cache_transient_lifetime, the default value is 12 * HOUR_IN_SECONDS –  brasofilo Mar 15 '13 at 19:46
    
The feeds doesn't show any visual data like any photo or video!! –  10wtaylor Mar 15 '13 at 19:49
    
That a matter for another Question, taylor ;) But confirm that the raw feed contain these elements. –  brasofilo Mar 15 '13 at 19:56

You can set your widget to be of a maximum height using CSS, and then add a scroll bar to it if you wish. It's a bit of an outdated way of doing things though, and may look a bit 'naff'.

Untested, but this should do the job -

div.rss-widget{
    max-height: 300px;
    overflow: scroll;
    overflow-x: hidden;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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