Recent Network Posts pagination

Hi, I am trying to add pagination to the Recent Network Posts plugin shortcode. For example I would like to list ~ 30 recent posts, and then have pagination to link to the rest. Can anyone advise on this?

  • Jack Kitterhing

    Hi there @glocare

    I hope you are well today, I'm afraid this will require custom coding, you may want to take a look at the Page Navi plugin here http://wordpress.org/plugins/wp-pagenavi/

    And that may work with minimal customization to the core code, though it will still require a bit of custom coding.

    Pagination would be a great addition to the plugin though, what does everyone else think?

    Thank you!

    Kind Regards
    Jack.

  • glocare

    Alright here it is. This shows the whole function "display_recent_posts", including how I modified the display of images, which may be useful to some as well. The pagination code is at the bottom.

    function display_recent_posts($tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,$tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,$tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes', $tmp_avatar_size = 16, $posttype = 'post', $output = true) {
    
    		global $network_query, $network_post;
    		$network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number, 'paged' => get_query_var('page')
                       ) );
    		?>
    		<style>
    			.post-box ul {
    				list-style: none;
    			}
    
    			.post-box li {
    				float: left;
    				padding-right: 20px;
    				padding-bottom: 10px;
    				width: 165px;
    			}
    			.active_page {
    				font-weight:bold;
    			}
    
    		</style>
    		<?php	
    
    		$html = '';
    
    		if( network_have_posts() ) {
    
    			$html .= $tmp_global_before;
    			$default_avatar = get_option('default_avatar');
    
    			while( network_have_posts()) {
    
    				network_the_post();
    				$posttype = $network_post->post_type;
    				$the_content = $network_post->post_content;
    				$string = $the_content;
    
    				if ($posttype == 'video') {
    					if (strpos($string,'entryid="') !== false) {
    						$start = 'entryid="';
    						$end = '"';
    						$string = " ".$string;
    						$ini = strpos($string,$start);
    						$ini += strlen($start);
    						$len = strpos($string,$end,$ini) - $ini;
    						$kaltura_thumb = substr($string,$ini,$len);				
    
    						if($kaltura_thumb != "") {
    							$img_src = "http://glovue.me/p/1/sp/1/thumbnail/entry_id/". $kaltura_thumb ."/version/0/vid_sec/60/width/160/height/101/type/5/bgcolor/000?1366591623621";
    						}
    						$imageSize=getimagesize($img_src);
    						if(!is_array($imageSize)) {
    							$img_src = "http://". GLOVUE_DOMAIN ."/public/glovue/images/defaults/show-160x112-eaeaea.jpg";
    						}
    					}
    
    				}
    				elseif ($posttype == 'channel') {	
    
    					$blog_id = $network_post->BLOG_ID;
    					global $wpdb;
    					switch_to_blog($blog_id);
    					$already_has_thumb = has_post_thumbnail($network_post->ID);
    					if ($already_has_thumb)  {
    						$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($network_post->ID), '160x101' );
    						$img_src = $thumb['0'];
    					} else {
    						$img_src = "http://". GLOVUE_DOMAIN ."/public/glovue/images/defaults/show-160x112-eaeaea.jpg";
    					}
    					 restore_current_blog();
    				}
    
    				$html .= $tmp_before;
    					$the_title = network_get_the_title();
    				if ( $tmp_title_characters > 0 ) {
    					$html .= $tmp_title_before;
    					if ( $tmp_show_avatars == 'yes' ) {
    						$the_author = network_get_the_author_id();
    						// $html .= get_avatar( $the_author, $tmp_avatar_size, $default_avatar) . ' ';
    						// Change Avatar to desired image source with link
    						$html .='<a href="' . network_get_permalink() . '" ><img title="'. $the_title .'"  width="160" height="101" class="thumb" src="'. $img_src .'" /></a>';
    					}					
    
    					if ( $tmp_title_link == 'no' ) {
    						$html .= substr($the_title,0,$tmp_title_characters);
    					} else {
    						$html .= '<br /><a title="'. $the_title .'" href="' . network_get_permalink() . '" >' . substr($the_title,0,$tmp_title_characters) . '</a>';
    					}
    
    					$html .= $tmp_title_after;
    				}
    				$html .= $tmp_title_content_divider;
    
    				if ( $tmp_content_characters > 0 ) {
    					$the_content = network_get_the_content();
    					$html .= substr(strip_tags($the_content),0,$tmp_content_characters);
    				}
    				$html .= $tmp_after;
    			}
    
    		}
    			$html .= $tmp_global_after;
    			// Pagination
    			global $page;
    			$network_query_count = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => -1, 'paged' => get_query_var('page')) );
    			$total_count = count($network_query_count);
    			$pages = ceil($total_count / $tmp_number);	
    
    			$html .= "<div style='clear: both;'></div>";
    			$paginarea = '<div class="paginarea">';
    			if (($page) != 1) { //Previous Page Link
    				$paginarea .= '<a href="?' . $filterstr . '&page=' . ($page - 1) .'"><</a>';
    			}
    			for($i=1;$i<=$pages;$i++) {
    				if(($page)==$i) {
    					$paginarea .= '<span class="active_page">';
    				}
    				$paginarea .= '<a href="?' . $filterstr . '&page='. $i .'">&nbsp;&nbsp; ';
    				$paginarea .= '  ' . $i . '  ';
    				$paginarea .= ' </a>';
    				if(($page)==$i) {
    					$paginarea .= '</span>';
    				}
    			}
    			if (($page) < $pages) { //Next Page Link
    				$paginarea .= '<a href="?' . $filterstr . '&page=' . ($page + 1) .'">&nbsp;&nbsp;></a>';
    			}
    			$paginarea .= '</div>';
    			echo $paginarea;
    			echo "<br />";
    			$html .= $paginarea;
    			// End Pagination
    			if($output) {
    				echo $html;
    			} else {
    				return $html;
    			}
    	}

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.