Advertisement
sagive

Get posts from blog network

Jul 11th, 2012
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 37.21 KB | None | 0 0
  1.    function network_latest_posts($how_many=10, $how_long=0, $titleOnly=true, $begin_wrap="\n<li>", $end_wrap="</li>", $blog_id='null', $thumbnail=false, $cpt="post", $ignore_blog='null', $cat='null', $tag='null', $paginate=false, $excerpt_length='null', $display_root=false) {
  2.         global $wpdb;
  3.         global $table_prefix;
  4.         $counter = 0;
  5.             $hack_cont = 0;
  6.             // Custom post type
  7.             $cpt = htmlspecialchars($cpt);
  8.             // Ignore blog or blogs
  9.             // if the user passes one value
  10.             if( !preg_match("/,/",$ignore_blog) ) {
  11.                 // Always clean this stuff ;)
  12.                 $ignore_blog = htmlspecialchars($ignore_blog);
  13.                 // Check if it's numeric
  14.                 if( is_numeric($ignore_blog) ) {
  15.                     // and put the sql
  16.                     $ignore = " AND blog_id != $ignore_blog ";
  17.                 }
  18.             // if the user passes more than one value separated by commas
  19.             } else {
  20.                 // create an array
  21.                 $ignore_arr = explode(",",$ignore_blog);
  22.                 // and repeat the sql for each ID found
  23.                 for($z=0;$z<count($ignore_arr);$z++){
  24.                     $ignore .= " AND blog_id != $ignore_arr[$z]";
  25.                 }
  26.             }
  27.         // get a list of blogs in order of most recent update. show only public and nonarchived/spam/mature/deleted
  28.         if ($how_long > 0) {
  29.                     // Select by blog id
  30.                     if( !empty($blog_id) && $blog_id != 'null' ) {
  31.                         $blog_id = htmlspecialchars($blog_id);
  32.                         $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
  33.                        public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'
  34.                        AND blog_id = $blog_id $ignore AND last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  35.                        ORDER BY last_updated DESC");
  36.                     } else {
  37.                         $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
  38.                        public = '1' $ignore AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'
  39.                        AND last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  40.                        ORDER BY last_updated DESC");                    
  41.                     }
  42.         } else {
  43.                     if( !empty($blog_id) && $blog_id != 'null' ) {
  44.                         $blog_id = htmlspecialchars($blog_id);
  45.                         $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
  46.                 public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND blog_id = $blog_id
  47.                 $ignore ORDER BY last_updated DESC");
  48.                     } else {
  49.                         $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
  50.                 public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'
  51.                 $ignore ORDER BY last_updated DESC");                  
  52.                     }
  53.         }
  54.    
  55.         if ($blogs) {
  56.                     // Count how many blogs we've found
  57.                     $nblogs = count($blogs);
  58.                     // Lets dig into each blog
  59.             foreach ($blogs as $blognlp) {
  60.                 // we need _posts and _options tables for this to work
  61.                             // Get the options table for each blog
  62.                             if( $display_root == true ) {
  63.                                 if( $blognlp == 1 ) {
  64.                                     $blogOptionsTable = $wpdb->base_prefix."options";
  65.                                     // Get the posts table for each blog
  66.                                     $blogPostsTable = $wpdb->base_prefix."posts";
  67.                                     // Get the terms relationships table for each blog
  68.                                     $blogTermRelationship = $wpdb->base_prefix."term_relationships";
  69.                                     // Get the term taxonomy table for each blog
  70.                                     $blogTermTaxonomy = $wpdb->base_prefix."term_taxonomy";
  71.                                     // Get the terms table for each blog
  72.                                     $blogTerms = $wpdb->base_prefix."terms";
  73.                                 } else {
  74.                                     $blogOptionsTable = $wpdb->base_prefix.$blognlp."_options";
  75.                                     // Get the posts table for each blog
  76.                                     $blogPostsTable = $wpdb->base_prefix.$blognlp."_posts";
  77.                                     // Get the terms relationships table for each blog
  78.                                     $blogTermRelationship = $wpdb->base_prefix.$blognlp."_term_relationships";
  79.                                     // Get the term taxonomy table for each blog
  80.                                     $blogTermTaxonomy = $wpdb->base_prefix.$blognlp."_term_taxonomy";
  81.                                     // Get the terms table for each blog
  82.                                     $blogTerms = $wpdb->base_prefix.$blognlp."_terms";
  83.                                 }
  84.                             } else {
  85.                                 $blogOptionsTable = $wpdb->base_prefix.$blognlp."_options";
  86.                                 // Get the posts table for each blog
  87.                                 $blogPostsTable = $wpdb->base_prefix.$blognlp."_posts";
  88.                                 // Get the terms relationships table for each blog
  89.                                 $blogTermRelationship = $wpdb->base_prefix.$blognlp."_term_relationships";
  90.                                 // Get the term taxonomy table for each blog
  91.                                 $blogTermTaxonomy = $wpdb->base_prefix.$blognlp."_term_taxonomy";
  92.                                 // Get the terms table for each blog
  93.                                 $blogTerms = $wpdb->base_prefix.$blognlp."_terms";
  94.                             }
  95.                             // --- Because the categories and tags are handled the same way by WP
  96.                             // --- I'm hacking the $cat variable so I can use it for both without
  97.                             // --- repeating the code
  98.                             if( !empty($cat) && $cat != 'null' && (empty($tag) || $tag == 'null') ) {         // Categories
  99.                                 $cat_hack = $cat;
  100.                                 $taxonomy = "taxonomy = 'category'";
  101.                             } elseif( !empty($tag) && $tag != 'null' && (empty($cat) || $cat == 'null') ) {   // Tags
  102.                                 $cat_hack = $tag;
  103.                                 $taxonomy = "taxonomy = 'post_tag'";
  104.                             } elseif( !empty($cat) && $cat != 'null' && !empty($tag) && $tag != 'null' ) {  // Categories & Tags
  105.                                 $cat_hack = $cat.",".$tag;
  106.                                 $taxonomy = "(taxonomy = 'category' OR taxonomy = 'post_tag')";
  107.                             }
  108.                             // --- Categories
  109.                             if( !empty($cat_hack) && $cat_hack != 'null' ) {
  110.                                 if( !preg_match('/,/',$cat_hack) ) {
  111.                                     $cat_hack = htmlspecialchars($cat_hack);
  112.                                     // Get the category's ID
  113.                                     $catid = $wpdb->get_results("SELECT term_id FROM $blogTerms WHERE slug = '$cat_hack'");
  114.                                     $cats{$blognlp} = $catid[0]->term_id;
  115.                                 } else {
  116.                                     $cat_arr = explode(',',$cat_hack);
  117.                                     for($x=0;$x<count($cat_arr);$x++){
  118.                                         $cat_ids = $wpdb->get_results("SELECT term_id FROM $blogTerms WHERE slug = '$cat_arr[$x]' ");
  119.                                         if( !empty($cat_ids[0]->term_id) ) {
  120.                                             // Get the categories' IDs
  121.                                             $catsa{$blognlp}[] = $cat_ids[0]->term_id;
  122.                                         }
  123.                                     }
  124.                                 }
  125.                             }
  126.                             // Let's find the ID for the category(ies) or tag(s)
  127.                             if( count($cats{$blognlp}) == 1 ) {
  128.                                 $taxo = $wpdb->get_results("SELECT term_taxonomy_id FROM $blogTermTaxonomy WHERE $taxonomy AND term_id = ".$cats{$blognlp});
  129.                                 $taxs{$blognlp} = $taxo[0]->term_taxonomy_id;
  130.                             } elseif( count($catsa{$blognlp}) >= 1 ) {
  131.                                 for( $y = 0; $y < count($catsa{$blognlp}); $y++ ) {
  132.                                     $tax_id = $wpdb->get_results("SELECT term_taxonomy_id FROM $blogTermTaxonomy WHERE $taxonomy AND term_id = ".$catsa{$blognlp}[$y]);
  133.                                     if( !empty($tax_id[0]->term_taxonomy_id) ) {
  134.                                         $taxsa{$blognlp}[] = $tax_id[0]->term_taxonomy_id;
  135.                                     }
  136.                                 }
  137.                             }
  138.                             // Next, let's find how they are related to the posts
  139.                             if( count($taxs{$blognlp}) == 1 ) {
  140.                                 $pids = $wpdb->get_results("SELECT object_id FROM $blogTermRelationship WHERE term_taxonomy_id = ".$taxs{$blognlp});
  141.                                 for( $w=0;$w<count($pids);$w++ ) {
  142.                                     $postids{$blognlp}[] = $pids[$w]->object_id;
  143.                                 }
  144.                             } elseif( count($taxsa{$blognlp}) >= 1 ) {
  145.                                 for( $w = 0; $w < count($taxsa{$blognlp}); $w++ ) {
  146.                                     $p_id = $wpdb->get_results("SELECT object_id FROM $blogTermRelationship WHERE term_taxonomy_id = ".$taxsa{$blognlp}[$w]);
  147.                                     for( $q = 0; $q < count($p_id); $q++ ){
  148.                                         $postidsa{$blognlp}[] = $p_id[$q]->object_id;
  149.                                     }
  150.                                 }
  151.                             }
  152.                             // Finally let's find the posts' IDs
  153.                             if( count($postids{$blognlp}) == 1 ) {
  154.                                 $filter_cat = " AND ID = ".$postids{$blognlp};
  155.                                 if(!empty($filter_cat)) {
  156.                                     if( !preg_match('/\(/',$filter_cat) ) {
  157.                                         $needle = ' AND ';
  158.                                         $replacement = ' AND (';
  159.                                         $filter_cat = str_replace($needle, $replacement, $filter_cat);
  160.                                     }
  161.                                 }
  162.                             } elseif( count($postids{$blognlp}) > 1 ) {
  163.                                 for( $v = 0; $v < count($postids{$blognlp}); $v++ ) {
  164.                                     if( $v == 0 && $hack_cont == 0 ) {
  165.                                         $filter_cat .= " AND ID = ".$postids{$blognlp}[$v];
  166.                                         $hack_cont++;
  167.                                     } elseif( $hack_cont > 0 ) {
  168.                                         $filter_cat .= " OR ID = ".$postids{$blognlp}[$v];
  169.                                     }
  170.                                 }
  171.                                 if(!empty($filter_cat)) {
  172.                                     if( !preg_match('/\(/',$filter_cat) ) {
  173.                                         $needle = ' AND ';
  174.                                         $replacement = ' AND (';
  175.                                         $filter_cat = str_replace($needle, $replacement, $filter_cat);
  176.                                     }
  177.                                 }
  178.                             } elseif( count($postidsa{$blognlp}) >= 1 ) {
  179.                                 for( $v = 0; $v < count($postidsa{$blognlp}); $v++ ) {
  180.                                     if( $v == 0 && $hack_cont == 0 ) {
  181.                                         $filter_cat .= " AND ID = ".$postidsa{$blognlp}[$v];
  182.                                         $hack_cont++;
  183.                                     } elseif( $hack_cont > 0 ) {
  184.                                         $filter_cat .= " OR ID = ".$postidsa{$blognlp}[$v];
  185.                                     }
  186.                                 }
  187.                                 if(!empty($filter_cat)) {
  188.                                     if( !preg_match('/\(/',$filter_cat) ) {
  189.                                         $needle = ' AND ';
  190.                                         $replacement = ' AND (';
  191.                                         $filter_cat = str_replace($needle, $replacement, $filter_cat);
  192.                                     }
  193.                                 }
  194.                             }
  195.                             // --- Categories\\
  196.                             // Get the saved options
  197.                 $options = $wpdb->get_results("SELECT option_value FROM
  198.                     $blogOptionsTable WHERE option_name IN ('siteurl','blogname')
  199.                     ORDER BY option_name DESC");
  200.                     // we fetch the title, excerpt and ID for the latest post
  201.                 if ($how_long > 0) {
  202.                                     if( !empty( $filter_cat ) && !empty($cat_hack) ) {
  203.                                         // Without pagination
  204.                                         if( !$paginate ) {
  205.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  206.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  207.                                                    $filter_cat )
  208.                                                    AND post_type = '$cpt'
  209.                                                    AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  210.                                                    ORDER BY id DESC LIMIT 0,$how_many");
  211.                                         // Paginated results
  212.                                         } else {
  213.                                             $posts_per_page = $how_many;
  214.                                             $page = isset( $_GET['pnum'] ) ? abs( (int) $_GET['pnum'] ) : 1;
  215.                                             $total_records = $wpdb->get_var("SELECT COUNT(ID)
  216.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  217.                                                    $filter_cat )
  218.                                                    AND post_type = '$cpt'
  219.                                                    AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  220.                                                    ORDER BY id DESC");
  221.                                             $total = $total_records;
  222.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  223.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  224.                                                    $filter_cat )
  225.                                                    AND post_type = '$cpt'
  226.                                                    AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  227.                                                    ORDER BY id DESC LIMIT ".(($page * $posts_per_page) - $posts_per_page) .",$posts_per_page");
  228.                                         }
  229.                                     } elseif( empty( $filter_cat ) && empty($cat_hack) ) {
  230.                                         // Without pagination
  231.                                         if( !$paginate ) {
  232.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  233.                                                FROM $blogPostsTable WHERE post_status = 'publish'
  234.                                                AND ID > 1
  235.                                                AND post_type = '$cpt'
  236.                                                AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  237.                                                ORDER BY id DESC LIMIT 0,$how_many");
  238.                                         // Paginated results
  239.                                         } else {
  240.                                             $posts_per_page = $how_many;
  241.                                             $page = isset( $_GET['pnum'] ) ? abs( (int) $_GET['pnum'] ) : 1;
  242.                                             $total_records = $wpdb->get_var("SELECT COUNT(ID)
  243.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  244.                                                    AND ID > 1
  245.                                                    AND post_type = '$cpt'
  246.                                                    AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  247.                                                    ORDER BY id DESC");
  248.                                             $total = $total_records;
  249.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  250.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  251.                                                    AND ID > 1
  252.                                                    AND post_type = '$cpt'
  253.                                                    AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  254.                                                    ORDER BY id DESC LIMIT ".(($page * $posts_per_page) - $posts_per_page) .",$posts_per_page");
  255.                                         }
  256.                                     }
  257.                 } else {
  258.                                     if( !empty( $filter_cat ) && !empty($cat_hack) ) {
  259.                                         // Without pagination
  260.                                         if( !$paginate ) {
  261.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  262.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  263.                                                    $filter_cat )
  264.                                                    AND post_type = '$cpt'
  265.                                                    ORDER BY id DESC LIMIT 0,$how_many");
  266.                                         // Paginated results
  267.                                         } else {
  268.                                             $posts_per_page = $how_many;
  269.                                             $page = isset( $_GET['pnum'] ) ? abs( (int) $_GET['pnum'] ) : 1;
  270.                                             $total_records = $wpdb->get_var("SELECT COUNT(ID)
  271.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  272.                                                    $filter_cat )
  273.                                                    AND post_type = '$cpt'
  274.                                                    ORDER BY id DESC");
  275.                                             $total = $total_records;
  276.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  277.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  278.                                                    $filter_cat )
  279.                                                    AND post_type = '$cpt'
  280.                                                    ORDER BY id DESC LIMIT ".(($page * $posts_per_page) - $posts_per_page) .",$posts_per_page");
  281.                                         }
  282.                                     } elseif( empty( $filter_cat ) && empty($cat_hack) ) {
  283.                                         // Without pagination
  284.                                         if( !$paginate ) {
  285.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  286.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  287.                                                    AND ID > 1
  288.                                                    AND post_type = '$cpt'
  289.                                                    ORDER BY id DESC LIMIT 0,$how_many");
  290.                                         } else {
  291.                                             $posts_per_page = $how_many;
  292.                                             $page = isset( $_GET['pnum'] ) ? abs( (int) $_GET['pnum'] ) : 1;
  293.                                             $total_records = $wpdb->get_var("SELECT COUNT(ID)
  294.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  295.                                                    AND ID > 1
  296.                                                    AND post_type = '$cpt'
  297.                                                    ORDER BY id DESC");
  298.                                             $total = $total_records;
  299.                                             $thispost = $wpdb->get_results("SELECT ID, post_title, post_excerpt
  300.                                                    FROM $blogPostsTable WHERE post_status = 'publish'
  301.                                                    AND ID > 1
  302.                                                    AND post_type = '$cpt'
  303.                                                    ORDER BY id DESC LIMIT ".(($page * $posts_per_page) - $posts_per_page) .",$posts_per_page");
  304.                                         }
  305.                                     }
  306.                 }
  307.                 // if it is found put it to the output
  308.                 if($thispost) {
  309.                                     // Remember we are doing this for multiple blogs?, well we need to display
  310.                                     // the number of posts chosen for each of them
  311.                                     for($i=0; $i < count($thispost); $i++) {
  312.                                         // get permalink by ID.  check wp-includes/wpmu-functions.php
  313.                                         $thispermalink = get_blog_permalink($blognlp, $thispost[$i]->ID);
  314.                                         // If we want to show the excerpt, we do this
  315.                                         if ($titleOnly == false || $titleOnly == 'false') {
  316.                                             // Widget list
  317.                                             if( ( !empty($begin_wrap) || $begin_wrap != '' ) && preg_match("/\bli\b/",$begin_wrap) && $thumbnail == false ) {
  318.                                                 echo $begin_wrap.'<div class="network-posts blog-'.$blognlp.'"><a href="'
  319.                                                 .$thispermalink.'">'.$thispost[$i]->post_title.'</a><span class="network-posts-source"> '.esc_html__('published in','eGallery').' <a href="'
  320.                                                 .$options[0]->option_value.'">'
  321.                                                 .$options[1]->option_value.'</a></span><p class="network-posts-excerpt">'.the_excerpt().'</p></div>'.$end_wrap;
  322.                                             // Shortcode
  323.                                             } else {
  324.                                                 // Display thumbnail
  325.                                                 if( $thumbnail ) {
  326.                                                     if( $i == 0 ) {
  327.                                                         echo '<div id="wrapper-'.$blognlp.'">';
  328.                                                     }
  329.                                                     echo $begin_wrap.'<div class="network-posts blog-'.$blognlp.'"><h1 class="network-posts-title"><a href="'
  330.                                                     .$thispermalink.'">'.$thispost[$i]->post_title.'</a></h1><span class="network-posts-source"> '.__('published in','trans-nlp').' <a href="'
  331.                                                     .$options[0]->option_value.'">'
  332.                                                     .$options[1]->option_value.'</a></span><a href="'
  333.                                                     .$thispermalink.'">'.the_post_thumbnail_by_blog($blognlp,$thispost[$i]->ID).'</a> <p class="network-posts-excerpt">'.custom_excerpt($excerpt_length, $thispost[$i]->post_excerpt, $thispermalink).'</p>';
  334.                                                     if( $i == (count($thispost)-1) && $paginate == true ) {
  335.                                                         echo '<div class="network-posts-pagination">';
  336.                                                         echo paginate_links( array(
  337.                                                             'base' => add_query_arg( 'pnum', '%#%' ),
  338.                                                             'format' => '',
  339.                                                             'prev_text' => __('&laquo;'),
  340.                                                             'next_text' => __('&raquo;'),
  341.                                                             'total' => ceil($total / $posts_per_page),
  342.                                                             'current' => $page,
  343.                                                             'type' => 'list'
  344.                                                         ));
  345.                                                         echo '</div>';
  346.                                                         echo
  347.                                                         '<script type="text/javascript" charset="utf-8">
  348.                                                            jQuery(document).ready(function(){
  349.    
  350.                                                                    jQuery(".blog-'.$blognlp.' .network-posts-pagination a").live("click", function(e){
  351.                                                                            e.preventDefault();
  352.                                                                            var link = jQuery(this).attr("href");
  353.                                                                            jQuery("#wrapper-'.$blognlp.'").html("<img src=\"'.plugins_url('/img/loader.gif', __FILE__) .'\" />");
  354.                                                                            jQuery("#wrapper-'.$blognlp.'").load(link+" .blog-'.$blognlp.'");
  355.    
  356.                                                                    });
  357.    
  358.                                                            });
  359.                                                        </script>';
  360.                                                     }
  361.                                                     echo "</div>".$end_wrap;
  362.                                                     if($i == (count($thispost)-1)){
  363.                                                         echo "</div>";
  364.                                                     }
  365.                                                 // Without thumbnail
  366.                                                 } else {
  367.                                                     if( $i == 0 ) {
  368.                                                         echo '<div id="wrapper-'.$blognlp.'">';
  369.                                                     }
  370.                                                     echo $begin_wrap.'<div class="network-posts blog-'.$blognlp.'"><h1 class="network-posts-title"><a href="'
  371.                                                     .$thispermalink.'">'.$thispost[$i]->post_title.'</a></h1><span class="network-posts-source"> '.__('published in','trans-nlp').' <a href="'
  372.                                                     .$options[0]->option_value.'">'
  373.                                                     .$options[1]->option_value.'</a></span><p class="network-posts-excerpt">'.custom_excerpt($excerpt_length, $thispost[$i]->post_excerpt, $thispermalink).'</p>';
  374.                                                     if( $i == (count($thispost)-1) && $paginate == true ) {
  375.                                                         echo '<div class="network-posts-pagination">';
  376.                                                         echo paginate_links( array(
  377.                                                             'base' => add_query_arg( 'pnum', '%#%' ),
  378.                                                             'format' => '',
  379.                                                             'prev_text' => __('&laquo;'),
  380.                                                             'next_text' => __('&raquo;'),
  381.                                                             'total' => ceil($total / $posts_per_page),
  382.                                                             'current' => $page,
  383.                                                             'type' => 'list'
  384.                                                         ));
  385.                                                         echo '</div>';
  386.                                                         echo
  387.                                                         '<script type="text/javascript" charset="utf-8">
  388.                                                            jQuery(document).ready(function(){
  389.    
  390.                                                                    jQuery(".blog-'.$blognlp.' .network-posts-pagination a").live("click", function(e){
  391.                                                                            e.preventDefault();
  392.                                                                            var link = jQuery(this).attr("href");
  393.                                                                            jQuery("#wrapper-'.$blognlp.'").html("<img src=\"'.plugins_url('/img/loader.gif', __FILE__) .'\" />");
  394.                                                                            jQuery("#wrapper-'.$blognlp.'").load(link+" .blog-'.$blognlp.'");
  395.    
  396.                                                                    });
  397.    
  398.                                                            });
  399.                                                        </script>';
  400.                                                     }
  401.                                                     echo "</div>".$end_wrap;
  402.                                                     if($i == (count($thispost)-1)){
  403.                                                         echo "</div>";
  404.                                                     }
  405.                                                 }
  406.                                             }
  407.                                         // Otherwise we just show the titles (useful when used as a widget)
  408.                                         } else {
  409.                                             // Widget list
  410.                                             if( $i == 0 ) {
  411.                                                 echo '<div id="wrapperw-'.$blognlp.'">';
  412.                                             }
  413.                                             if( preg_match("/\bli\b/",$begin_wrap) ) {
  414.                                                 echo $begin_wrap.'<div class="network-posts blogw-'.$blognlp.'"><a href="'.$thispermalink
  415.                                                 .'">'.$thispost[$i]->post_title.'</a>';
  416.                                                 if( $i == (count($thispost)-1) && $paginate == true ) {
  417.                                                     echo '<div class="network-posts-pagination">';
  418.                                                     echo paginate_links( array(
  419.                                                         'base' => add_query_arg( 'pnum', '%#%' ),
  420.                                                         'format' => '',
  421.                                                         'show_all' => false,
  422.                                                         'prev_text' => __('&laquo;'),
  423.                                                         'next_text' => __('&raquo;'),
  424.                                                         'total' => ceil($total / $posts_per_page),
  425.                                                         'current' => $page,
  426.                                                         'type' => 'list'
  427.                                                     ));
  428.                                                     echo '</div>';
  429.                                                     echo
  430.                                                     '<script type="text/javascript" charset="utf-8">
  431.                                                        jQuery(document).ready(function(){
  432.    
  433.                                                                jQuery(".blogw-'.$blognlp.' .network-posts-pagination a").live("click", function(e){
  434.                                                                        e.preventDefault();
  435.                                                                        var link = jQuery(this).attr("href");
  436.                                                                        jQuery("#wrapperw-'.$blognlp.'").html("<img src=\"'.plugins_url('/img/loader.gif', __FILE__) .'\" />");
  437.                                                                        jQuery("#wrapperw-'.$blognlp.'").load(link+" .blogw-'.$blognlp.'");
  438.    
  439.                                                                });
  440.    
  441.                                                        });
  442.                                                    </script>';
  443.                                                 }
  444.                                                 echo '</div>'.$end_wrap;
  445.                                                 if($i == (count($thispost)-1)){
  446.                                                     echo "</div>";
  447.                                                 }
  448.                                             // Shortcode
  449.                                             } else {
  450.                                                 if( $i == 0 ) {
  451.                                                     echo '<div id="wrapper-'.$blognlp.'">';
  452.                                                 }
  453.                                                 echo $begin_wrap.'<div class="network-posts blog-'.$blognlp.'"><h1 class="network-posts-title"><a href="'.$thispermalink
  454.                                                 .'">'.$thispost[$i]->post_title.'</a></h1>';
  455.                                                 if( $i == (count($thispost)-1) && $paginate == true ) {
  456.                                                     echo '<div class="network-posts-pagination">';
  457.                                                     echo paginate_links( array(
  458.                                                         'base' => add_query_arg( 'pnum', '%#%' ),
  459.                                                         'format' => '',
  460.                                                         'prev_text' => __('&laquo;'),
  461.                                                         'next_text' => __('&raquo;'),
  462.                                                         'total' => ceil($total / $posts_per_page),
  463.                                                         'current' => $page,
  464.                                                         'type' => 'list'
  465.                                                     ));
  466.                                                     echo '</div>';
  467.                                                     echo
  468.                                                     '<script type="text/javascript" charset="utf-8">
  469.                                                        jQuery(document).ready(function(){
  470.    
  471.                                                                jQuery(".blog-'.$blognlp.' .network-posts-pagination a").live("click", function(e){
  472.                                                                        e.preventDefault();
  473.                                                                        var link = jQuery(this).attr("href");
  474.                                                                        jQuery("#wrapper-'.$blognlp.'").html("<img src=\"'.plugins_url('/img/loader.gif', __FILE__) .'\" />");
  475.                                                                        jQuery("#wrapper-'.$blognlp.'").load(link+" .blog-'.$blognlp.'");
  476.    
  477.                                                                });
  478.    
  479.                                                        });
  480.                                                    </script>';
  481.                                                 }
  482.                                                 echo '</div>'.$end_wrap;
  483.                                                 if($i == (count($thispost)-1)){
  484.                                                     echo "</div>";
  485.                                                 }
  486.                                             }
  487.                                         }
  488.                                     }
  489.                                     // Count only when all posts has been displayed
  490.                                     $counter++;
  491.                 }
  492.                 // don't go over the limit of blogs
  493.                 if($counter >= $nblogs) {
  494.                                 break;
  495.                 }
  496.             }
  497.         }
  498.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement