/** * Lista no blog * */ function panamazonica_posts_rede() { restore_current_blog(); global $blog_id, $post; ?> <div class="acontece over loop cf"> <h3 class="area-title"><?php _e('Latest news', 'panamazonica'); ?> </h3> <?php $this_blog_id = $blog_id; // Realiza a query no blog principal switch_to_blog(1); $rede = new WP_Query(array('posts_per_page' => 4, 'ignore_sticky_posts' => 1, 'meta_key' => '_original_blog_id', 'meta_value' => $this_blog_id, 'meta_compare' => '!=')); if ($rede->have_posts()) { while ($rede->have_posts()) { $rede->the_post(); ?> <article class="hentry"> <h2 class="entry-title"> <a href="<?php the_permalink(); ?> "> <?php $this_post_id = $post->ID; $original_ids = panamazonica_get_original_ids(); // Busca o post thumbnail no blog original e depois volta para o site da rede switch_to_blog($original_ids['blog_id']); echo get_the_post_thumbnail($original_ids['post_id'], 'post-pequeno'); switch_to_blog(1); the_title(); ?> <small> <?php $original_blog_id = $original_ids ? $original_ids['blog_id'] : 1; /* translators: author and blog name (example: Por Leonardo em Telessaúde) */ printf(__('By %1$s in %2$s', 'panamazonica'), get_the_author(), get_blog_details($original_ids['blog_id'])->blogname); ?> </small> </a> </h2> </article> <?php } } switch_to_blog($this_blog_id); ?> </div><!-- /acontece --> <?php }
?> <div class="slider-wrapper"> <div class="slider"> <?php $query = new WP_Query(array('posts_per_page' => 5, 'ignore_sticky_posts' => 1, 'meta_key' => '_home', 'meta_value' => 1)); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $original_blog_id = get_post_meta($post->ID, '_original_blog_id', true); $original_post_id = get_post_meta($post->ID, '_original_post_id', true); ?> <div class="media slide cf"> <div class="img entry-image"> <?php if ($original_ids = panamazonica_get_original_ids()) { switch_to_blog($original_ids['blog_id']); echo get_the_post_thumbnail($original_ids['post_id'], 'post-grande'); restore_current_blog(); } else { the_post_thumbnail('post-grande'); } ?> </div> <div class="bd"> <h2 class="entry-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?>
/** * Outputs the HTML for this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void Echoes it's output **/ function widget($args, $instance) { global $wpdb, $blog_id; $cache = wp_cache_get('widget_acontece_rede', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = null; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args, EXTR_SKIP); $title = apply_filters('widget_title', empty($instance['title']) ? __('Latest news', 'panamazonica') : $instance['title'], $instance, $this->id_base); // Número de posts if (!isset($instance['number'])) { $instance['number'] = '3'; } if (!($number = absint($instance['number']))) { $number = 3; } // Parâmetros iniciais $args = array('post_type' => 'post', 'posts_per_page' => $number, 'post_status' => 'publish'); if ($blog_id > 1) { $current_blog = $blog_id; $args['meta_query'] = array(array('key' => '_original_blog_id', 'value' => $current_blog, 'compare' => '!=')); switch_to_blog(1); } // Excluindo na mão os posts destaque. Definir uma front page, por exemplo, já muda a main query if ($blog_id == 1 && (is_front_page() || is_home())) { $exclude = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_home' AND meta_value = '1'"); $args['post__not_in'] = $exclude; } $acontece_rede = new WP_Query($args); if ($acontece_rede->have_posts()) { echo $before_widget; echo $before_title; echo $title; echo $after_title; while ($acontece_rede->have_posts()) { $acontece_rede->the_post(); ?> <article> <h2 class="entry-title"> <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> <small> <?php $original_blog_id = ($original_ids = panamazonica_get_original_ids()) ? $original_ids['blog_id'] : 1; /* translators: author and blog name (example: Por Leonardo em Telessaúde) */ printf(__('By %1$s in %2$s', 'panamazonica'), get_the_author(), get_blog_details($original_ids['blog_id'])->blogname); ?> </small> </a> </h2> </article> <?php } // Final do widget echo $after_widget; // Reinicia o postdata wp_reset_postdata(); } // if ( have_posts() ) restore_current_blog(); $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_acontece_rede', $cache, 'widget'); }