Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class recentproshortcode {
- var $build = 1;
- var $db;
- function __construct() {
- global $wpdb;
- $this->db =& $wpdb;
- if($this->db->blogid == 1) {
- // Only add the feed for the main site
- add_action('init', array(&$this, 'initialise_recentproshortcode') );
- }
- add_shortcode( 'globalproposts', array( &$this, 'display_pro_posts_shortcode') );
- }
- function recentproshortcode() {
- $this->__construct();
- }
- function initialise_recentproshortcode() {
- // In case we need it in future :)
- }
- function display_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) {
- global $network_query, $network_post, $wpdb;
- // http://premium.wpmudev.org/forums/topic/restricting-specific-page-templates-within-prosites#post-652329
- $network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number ));
- $html = '';
- global $wpdb;
- $blog_id = $wpdb->blogid;
- $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
- $level = $wpdb->get_var( $sql );
- $pro = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE level = 1");
- $temp = array();
- foreach( $pro as $p ){
- array_push( $temp, $p->blog_ID );
- }
- // if ( $level == 2 ) {
- $html .= $tmp_global_before;
- while( network_have_posts() ) {
- network_the_post();
- if( ! in_array( $network_post->BLOG_ID, $temp ) ) continue;
- switch_to_blog( $network_post->BLOG_ID );
- //Get network blog post featured image
- $n_post = network_get_post();
- // }
- $featured_image = get_the_post_thumbnail( $n_post->ID, 'large' );
- //Network blog name
- $blogname = get_blog_option( $network_post->BLOG_ID, 'blogname' );
- restore_current_blog();
- $html .= $tmp_before;
- $html .= $tmp_title_before . '<a href="' . network_get_permalink() . '" class="crop">';
- $the_title = network_get_the_title();
- $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>';
- $tile_img = '';
- if(!empty($featured_image)) {
- $tile_img = $featured_image;
- } else {
- $options = get_option( 'bpb_settings' );
- // $tile_img = '<img src="' . plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) . '" >';
- // $tile_img = '<img src="' . get_option( $bpb_placehold_it , plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) ). '" >';
- $tile_img = '<img src="' . $options['bpb_btn_6'] . '" >';
- }
- if ( $tmp_title_characters > 0 ) {
- $html .= $tile_img;
- $html .= $tmp_title_after;
- }
- $html .= $tmp_after;
- }
- $html .= $tmp_global_after;
- // }
- if($output) {
- echo $html;
- } else {
- return $html;
- }
- }
- function display_pro_posts_shortcode($atts, $content = null, $code = "") {
- $defaults = array( 'number' => 28,
- 'title_characters' => 35,
- 'content_characters' => 50,
- 'title_content_divider' => '<br />',
- 'title_before' => '<div>',
- 'title_after' => '</div>',
- 'global_before' => '<ul>',
- 'global_after' => '</ul>',
- 'before' => '<li class="crop-square">',
- 'after' => '</a></li>',
- 'title_link' => 'yes',
- 'show_avatars' => 'no',
- 'show_images' => 'yes',
- 'avatar_size' => 16,
- 'posttype' => 'post'
- );
- extract(shortcode_atts($defaults, $atts));
- $html = '';
- $html .= $this->display_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);
- return $html;
- }
- }
- function display_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) {
- global $recentproshortcode;
- $recentproshortcode->display_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 );
- }
- $recentproshortcode = new recentproshortcode();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement