Support » Plugin: Fancy Github Activity » Can’t show more than 30 events

  • The shortcode attribute “limit” only works to set the limit to 30, but no higher. That’s because it seems the API call only fetches 30 items, and the “limit” just limits how many of those 30 items are displayed.
    So if you ask for 40 items, it only fetches 30 and then iterates over that list, planning on show you 40 of the 30 items… so basically it only ever shows you 30 items.
    Also, GitHub’s API imposes a limit of only querying up to 100 items at a time. For my personal usage, I wanted to be able to look as far back as I wanted. So I added some buttons to show the “next” page-worth of items. Here’s my my modified fancy_github_activity_code() function that solves both of these issues,

    function fancy_github_activity_code( $atts ) {
    $atts = shortcode_atts(
    			'username' => 'stopspazzing',
    			'repository' => '',
          'limit' => '20',
    		), $atts, 'fancy-github-activity' );
    	$page = isset($_GET['gh_page']) ? $_GET['gh_page'] : 1;
    	global $wp;
    	$next_url =
    			$page + 1,
      <div id="fancy-github-activity-feed"></div>
    	<a href="<?php echo $next_url;?>">Next Page</a>
        var name = "<?php echo $atts['username'];?>";
        var rep = "<?php echo $atts['repository'];?>";
        var max = <?php echo $atts['limit'];?>;
          username: name,
          repository: rep, // optional
          selector: "#fancy-github-activity-feed",
          limit: max, // optional
    	    eventsUrl: '' + name + '/events?per_page=' + max + '&page=' + <?php echo $page;?>

    Notice taht it sets the “eventsUrl” to use the limit, adds a link that says “Next” (which just links to the current page, but adds a querystring variable called “gh_page” to indicate we want the next page-worth), and looks for a querystring variable called “gh_page” to know what “page” of GitHub activity to show.

    Don’t feel obliged to accept this as-is, more as inspiration

  • The topic ‘Can’t show more than 30 events’ is closed to new replies.