WordPress.org

Ready to get started?Download WordPress

Forums

WordPress RSS Shortcode
[resolved] [Plugin: WordPress RSS Shortcode] Limit RSS Feed Quantity (7 posts)

  1. inhouse
    Member
    Posted 2 years ago #

    Hi, I'm using the WordPress RSS Shortcode plugin and I am wondering how I can limit the quantity of posts that come in. So far I don't see this option and I've googled how to do modify the code myself with no luck. Thanks in advance!

    This is the code so far:

    function rsstag($atts) {
    	$atts = shortcode_atts(array(
    		'url' => get_bloginfo('rss2_url'),
    		'show_author' => 0,
    		'show_date' => 1,
    		'show_summary' => 0
    	), $atts);
    	//var_dump($atts);
    	ob_start();
    	wp_widget_rss_output($atts['url'], $atts);
    	$rss = ob_get_contents();
    	ob_end_clean();
    	return $rss;
    }
    add_shortcode('rsstag', 'rsstag');

    http://wordpress.org/extend/plugins/wordpress-rss-shortcode/

  2. katmac_aus
    Member
    Posted 2 years ago #

    This RSS looked great as you could have date as option but I also need to set a limit!

    Hope to hear an answer soon.

  3. carlfj
    Member
    Posted 2 years ago #

    The plugin from yoast.com has this function. But not the ability to show author or date.
    http://wordpress.org/extend/plugins/rss-shortcode/

    I modified it for my own use so I could change the list format to just add custom delimiters instead, in this case commas. Furthermore the ability to skip some of the posts, e.g. to be able to just show post 6-10.

    Let me know if this extension is to any use for you, I'd be happy to share it.

    Regards, Carl

  4. scamartist26
    Member
    Posted 1 year ago #

    Hey guys, a couple things about this that I have found.

    1. To limit item entries, the code should be changed to this:

    function rsstag($atts) {
    	$atts = shortcode_atts(array(
    		'url' => get_bloginfo('rss2_url'),
                    'items' => '5',
    		'show_author' => 0,
    		'show_date' => 1,
    		'show_summary' => 0
    	), $atts);
    	//var_dump($atts);
    	ob_start();
    	wp_widget_rss_output($atts['url'], $atts);
    	$rss = ob_get_contents();
    	ob_end_clean();
    	return $rss;
    }
    add_shortcode('rsstag', 'rsstag');

    This defaults to 5 entries displayed, and will give you the ability to put items=# in the shortcode to put a manual limit of entries displayed.

    2. The URL must have AMPERSANDS encoded to %26 otherwise you may not get the correct feed.

    Cheers, hope that helps.

  5. scamartist26
    Member
    Posted 1 year ago #

    One other thing to note, the URL may note work if you put the comma delimiter at the end without a space.

    Example:
    WRONG [rsstag url=http://example.com, items=7]
    CORRECT [rsstag url=http://example.com , items=7]

  6. inhouse
    Member
    Posted 1 year ago #

    Right on, thanks a lot scamartist26. That works perfectly!

  7. scamartist26
    Member
    Posted 1 year ago #

    I may have been too speedy with my response here, LOL.

    My code is sloppy, there should not be the single quotes around the integer after the items key. Like so

    'items' => 5,

    It will still work, but is not best practice.

    Also, the shortcode does not need , delimiters, the documentation led me wrong. Those can be left out all together.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic