WordPress.org

Ready to get started?Download WordPress

Forums

WP RSS Aggregator
[resolved] Limiting feed in template (14 posts)

  1. voglermc
    Member
    Posted 1 year ago #

    I'm using this in my template
    <?php wprss_display_feed_items(); ?>

    How can I limit it to only 5 posts? I'm using the shortcode on a page and need to display 1000+

    Thanks!

    http://wordpress.org/extend/plugins/wp-rss-aggregator/

  2. jeangalea
    Member
    Plugin Author

    Posted 1 year ago #

    Through the plugin settings panel you can limit the number of feeds displayed.

  3. voglermc
    Member
    Posted 1 year ago #

    Yes but was wondering if there was more code that I could add to php call to limit it less than 1000 that I have it set in settings panel

  4. jeangalea
    Member
    Plugin Author

    Posted 1 year ago #

    No the settings panel is all there is. Can you explain why you'd like to do this so I'll have a better idea and maybe implement it in the next update?

  5. voglermc
    Member
    Posted 1 year ago #

    Thanks, my site runs a podcast every week and we have over 300+ I want to list on a page which I use your plugin for. On the homepage I only want to show the last 5. So I wanted to use your code above to show only 5 of the latest podcasts

  6. jeangalea
    Member
    Plugin Author

    Posted 1 year ago #

    Ah ok, I got it, I'm noting it down to implement for the next release. Definitely makes sense and we should also have this possible via shortcode.

  7. voglermc
    Member
    Posted 1 year ago #

    Thanks!

  8. stangill13
    Member
    Posted 1 year ago #

    I just made this exact change to the plugin. It only required updating a few lines of code in the /includes/feed-display.php file

    Change Line 173 to:

    $feed_items = wprss_get_feed_items_query( $settings, $args );

    Starting at Line 69, change the wprss_get_feed_items_query function to:

    function wprss_get_feed_items_query( $settings, $args = false ) {
    	// Arguments for the next query to fetch all feed items
    	$posts_per_page = (isset($args['feed_limit']) && $args['feed_limit'] > 0) ? $args['feed_limit'] : $settings['feed_limit'];
    	$feed_items_args = apply_filters(
    							'wprss_display_feed_items_query',
    							array(
    								'post_type'      => 'wprss_feed_item',
    								'posts_per_page' => $posts_per_page,
    								'orderby'        => 'meta_value',
    								'meta_key'       => 'wprss_item_date',
    								'order'          => 'DESC'
    							)
    	);
    
    	// Query to get all feed items for display
    	$feed_items = new WP_Query( $feed_items_args );
    
    	return $feed_items;
    }

    Works for me. Now I can set the limit in the shortcode like this: [wp_rss_aggregator feed_limit=5]. And it will default back to the widget setting if a limit isn't specified.

  9. voglermc
    Member
    Posted 1 year ago #

    I need just the opposite. I need the settings set at 900 and the code at the top of the page set to 5 not the shortcode

  10. stangill13
    Member
    Posted 1 year ago #

    The above changes to the plugin file would allow you to pass a limit through the shortcode. I use the following code in my template PHP file instead of the line you have in the original post:

    <?php echo do_shortcode("[wp_rss_aggregator feed_limit=5]"); ?>

    http://codex.wordpress.org/Function_Reference/do_shortcode

  11. voglermc
    Member
    Posted 1 year ago #

    Thanks ill try it soon

  12. stangill13
    Member
    Posted 1 year ago #

    Note: any changes you make to the plugin files will be overwritten when you update the plugin, but it sounds like the plugin author is going to add this in the next version. (Though he may not use the same method I did.)

    Also, be sure to save a back up copy of any files you change, because even a basic PHP error can take down your entire website.

  13. voglermc
    Member
    Posted 1 year ago #

    Works like a charm! Thank you so much, my project is close to completion because of this fix

  14. jeangalea
    Member
    Plugin Author

    Posted 1 year ago #

    This is coming in the next update.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.