Show recent/popular photos on user profile?

Hi there,

I would like to create a basic widget/loop that shows the most recent/popular uploads from a user. The current widget allows you to show global recent/popular uploads, so this is almost what I need :smile:

Thanks in advance!

Edit:

I have most of it working.

The only thing I need to figure out is how to limit the amount of images shown. I would like to limit to show a maximum of 5 recent photos.

@bowefrankema use the admin settings "Number of media per page " to control the number of media that will be dispalyed on your custom widget…

Wouldn’t that also be applied to the regular album pages? Isn’t there a query parameter I can give to the loop? (posts_per_page for example?)

@bowefrankema (posts_per_page) won’t work on your widget,but first of all, you would notice that your custom widget does not show up on buddypress pages with the slug (media). So this is what you can do,use this code:

add_filter( 'rtmedia_per_page_media', 'limit_widget_media_size');
function limit_widget_media_size( $admin_per_page ) {
   if ( is_page( you_bb_page_or_pages ) ){	
		$widget_per_page = 5;
		return $widget_per_page;
	}
       return $admin_per_page;
}

The above code will limit the media size of your custom widget on the specified bb-page or pages, not including the pages with the slug (media),and the "Number of media per page " option on your admin settings will not be affected on pages with the slug (media). I know this solution is not pretty, but should work. For future update we will try to make it easy for users to achieve this effect…

Thank you @barth, really helpful! I got the widget working displaying the right amount of pictures… the only thing I could not fix was the widget showing up on all pages except the buddypress user media pages. I looked at the conditionals and I don’t think there is one conditional available that only fires when viewing any “BuddyPress Media” page. I tried something like this

function cfc_media_widget()
{
if ( bp_is_user() || bp_is_user() && !is_rtmedia_album() || bp_is_user() && !is_rtmedia_album_gallery() || bp_is_user() && !is_rtmedia_single() ) :
	get_template_part( 'rtmedia/recent-photos' );
endif;
}
add_action( 'open_sidebar', 'cfc_media_widget' );

For now I’ve used some CSS to simply hide the widget (which does throw a fatal error like you mentioned). It’s not ideal but it certainly works.

It would be awesome if you’d could add a few query parameters in the plugin so making custom media loops is easier :slight_smile:

Thanks again for the amazing plugin, Bowe

@bowefrankema – You could wrap that in an if statement and only show if the $_SERVER[‘REQUEST_URI’] and if that contains the text “members” AND “media” then display the widget, otherwise show nothing.

http://php.net/manual/en/reserved.variables.server.php