Advertisement
Guest User

Untitled

a guest
Feb 25th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. Looking for sites at the Pro Level
  5.  
  6. */
  7.  
  8.  
  9. class proshortcode {
  10.  
  11. var $build = 1;
  12.  
  13. var $db;
  14.  
  15. function __construct() {
  16.  
  17. global $wpdb;
  18.  
  19. $this->db =& $wpdb;
  20.  
  21. if($this->db->blogid == 1) {
  22. // Only add the feed for the main site
  23. add_action('init', array(&$this, 'initialise_proshortcode') );
  24. }
  25.  
  26. add_shortcode( 'pro-posts', array( &$this, 'list_pro_posts_shortcode') );
  27.  
  28. }
  29.  
  30. function proshortcode() {
  31. $this->__construct();
  32. }
  33.  
  34. function initialise_proshortcode() {
  35. // In case we need it in future :)
  36. }
  37.  
  38. function list_pro_posts($tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,
  39. $tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,
  40. $tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes',
  41. $tmp_avatar_size = 16, $posttype = 'post', $output = true) {
  42.  
  43. global $network_query, $network_post, $wpdb;
  44.  
  45. /*
  46. http://www.smashingmagazine.com/2013/01/14/using-wp_query-wordpress/
  47. $args = array('cat' => 4);
  48. $category_posts = new WP_Query($args);
  49. */
  50.  
  51. // http://premium.wpmudev.org/forums/topic/restricting-specific-page-templates-within-prosites#post-652329
  52.  
  53. $network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number ));
  54.  
  55. $html = '';
  56.  
  57. global $wpdb;
  58. $blog_id = $wpdb->blogid;
  59. $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
  60. $level = $wpdb->get_var( $sql );
  61. $pro = "SELECT blog_ID FROM {$wpdb->base_prefix}pro_sites WHERE 'level' = 1 ";
  62.  
  63. $html .= $tmp_global_before;
  64.  
  65. while( network_have_posts( $pro ) ) {
  66. network_the_post();
  67.  
  68. switch_to_blog( $network_post->BLOG_ID );
  69.  
  70. //Get network blog post featured image
  71. $n_post = network_get_post();
  72. // }
  73. $featured_image = get_the_post_thumbnail( $n_post->ID, 'large' );
  74. //Network blog name
  75. $blogname = get_blog_option( $network_post->BLOG_ID, 'blogname' );
  76.  
  77. restore_current_blog();
  78. $html .= $tmp_before;
  79.  
  80. $html .= $tmp_title_before . '<a href="' . network_get_permalink() . '" class="no-crop">';
  81.  
  82. $the_title = network_get_the_title();
  83.  
  84. $html .= '<div id="npost-meta"><div class="blog-name">' . $blogname . '</div> <hr> <div id="net-post-title">' . substr($the_title,0,$tmp_title_characters) . '</div></div>';
  85.  
  86.  
  87.  
  88.  
  89. $html .= $tmp_after;
  90.  
  91. }
  92.  
  93.  
  94. if($output) {
  95. echo $html;
  96. } else {
  97. return $html;
  98. }
  99.  
  100. }
  101.  
  102. function list_pro_posts_shortcode($atts, $content = null, $code = "") {
  103.  
  104. $defaults = array( 'number' => 25,
  105. 'title_characters' => 25,
  106. 'content_characters' => 30,
  107. 'title_content_divider' => '<br />',
  108. 'title_before' => '<div>',
  109. 'title_after' => '</div>',
  110. 'global_before' => '<ul>',
  111. 'global_after' => '</ul>',
  112. 'before' => '<li class="crop-square">',
  113. 'after' => '</a></li>',
  114. 'title_link' => 'yes',
  115. 'show_avatars' => 'no',
  116. 'show_images' => 'yes',
  117. 'avatar_size' => 16,
  118. 'posttype' => 'post'
  119. );
  120.  
  121. extract(shortcode_atts($defaults, $atts));
  122.  
  123. $html = '';
  124.  
  125. $html .= $this->list_pro_posts( $number, $title_characters, $content_characters, $title_content_divider, $title_before, $title_after, $global_before, $global_after, $before, $after, $title_link, $show_avatars, $avatar_size, $posttype, false);
  126.  
  127. return $html;
  128.  
  129. }
  130.  
  131. }
  132.  
  133. function list_pro_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) {
  134. global $proshortcode;
  135.  
  136. $proshortcode->list_pro_posts( $tmp_number, $tmp_title_characters, $tmp_content_characters, $tmp_title_content_divider, $tmp_title_before, $tmp_title_after, $tmp_global_before, $tmp_global_after, $tmp_before, $tmp_after, $tmp_title_link, $tmp_show_avatars, $tmp_avatar_size, $posttype, $output );
  137. }
  138.  
  139. $proshortcode = new proshortcode();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement