Ejemplo n.º 1
0
function get_spotlight_posts()
{
    global $exclude_posts, $wpdb, $post;
    $cat_object = get_category_by_slug('spotlight-featured');
    $spotlight_featured = $cat_object->term_id;
    $main_featured_args = array('posts_per_page' => 1, 'cat' => $spotlight_featured, 'post_status' => 'publish');
    $main_featured_id = '';
    $main_featured_query = new WP_Query($main_featured_args);
    // is there a quicker way to get the ID?
    if ($main_featured_query->have_posts()) {
        $main_featured_id = $main_featured_query->posts[0]->ID;
    }
    exclude_this_post(1, $main_featured_id);
    $table_name = $wpdb->base_prefix . 'db_stats';
    $results = $wpdb->get_results("SELECT * FROM {$table_name}", ARRAY_A);
    if ($results) {
        // sort by views
        usort($results, function ($a, $b) {
            return $b['views'] - $a['views'];
        });
        $posts_to_query = array();
        $posts_added = 0;
        $blogs_added = array();
        $result_count = count($results);
        while (list($key, $post) = each($results)) {
            // remove day old posts
            if (strtotime($post['date_added']) < strtotime('-1 day')) {
                unset($results[$key]);
            }
            $blogID = $post['blog_id'];
            $post_id = $post['post_id'];
            if ($blogID == 1 && $post_id == $main_featured_id || $post_id == 1) {
                continue;
            }
            // if only one blog exists by the 3rd post skip till new blog ( so we don't have all posts from the same blog.. )
            if (count($posts_to_query) == 1 && $posts_added == 3 && $key + 1 < $result_count) {
                if (in_array($blogID, $blogs_added)) {
                    continue;
                }
            }
            $blogs_added[] = $blogID;
            $posts_to_query[$blogID][] = $post_id;
            $posts_added++;
            if ($posts_added == 6) {
                break;
            }
        }
    }
    $args = array('posts_per_page' => 10 - count($posts_to_query), 'post_status' => 'publish', 'post__in' => $posts_to_query, 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => 'db_views');
    $query = new WP_Query();
    $network_query = $query->posts = network_query_posts($args);
    $post_count = $query->post_count = count($network_query);
    $posts_looped = 0;
    while ($query->have_posts()) {
        $query->the_post();
        $blogID = $post->BLOG_ID;
        if ($posts_looped == 0 || $posts_looped == 3) {
            echo '<div class="col-md-3">';
        }
        if ($posts_looped != 2) {
            echo spotlight_post($blogID);
            $posts_looped++;
        }
        if ($posts_looped == 2 || $posts_looped == 5) {
            echo '</div>';
        }
        if ($posts_looped == 2) {
            while ($main_featured_query->have_posts()) {
                $main_featured_query->the_post();
                echo '<div class="col-md-6">';
                echo spotlight_post(1, array('center' => true));
                echo '</div>';
            }
            $posts_looped++;
        }
        if ($posts_looped == 5) {
            break;
        }
    }
    reset_blog();
}
Ejemplo n.º 2
0
function spotlight_post($blogID = 1, $args = array())
{
    min_switch_to_blog($blogID);
    $id = get_the_ID();
    exclude_this_post($blogID, $id);
    $defaults = array('center' => false);
    // merge arguments with defaults && set keys as variables
    $args = array_merge($defaults, $args);
    foreach ($args as $key => $val) {
        ${$key} = $val;
    }
    $new_title = get_post_meta($id, 'db_featured_title', true);
    $subtitle = get_post_meta($id, 'db_subtitle', true);
    $title = get_the_title();
    if (!empty($new_title)) {
        $title = $new_title;
    }
    $w = 450;
    $h = 450;
    $styles = '';
    if ($center) {
        $styles = ' main-spotlight';
        $w = 800;
        $h = 800;
    }
    $external = '';
    if ($blogID > 1) {
        $external = 'external-link';
    }
    ?>

	<article class="spotlight-post<?php 
    echo $styles;
    ?>
">
		<a href="<?php 
    the_permalink();
    ?>
">
			<div class="featured-image" data-src="<?php 
    echo get_thumb_url($w, $h);
    ?>
"><?php 
    /*<div class="spotlight-bg"></div><?php */
    ?>
</div>
		</a>
		<div class="caption">
			<?php 
    if ($blogID > 1) {
        ?>
			<h4>via <?php 
        echo blog_svg($blogID);
        ?>
</h4>
			<?php 
    }
    ?>

			<h1 class="<?php 
    echo $external;
    ?>
"><?php 
    echo $title;
    ?>
</h1>

			<?php 
    if (isset($subtitle) && $center == 1) {
        ?>
			<h2><?php 
        echo $subtitle;
        ?>
</h2>
			<?php 
    }
    ?>
		</div>
	</article>

	<?php 
}
Ejemplo n.º 3
0
/**
 * Single Default
 *
 */
global $exclude_posts;
if (have_posts()) {
    while (have_posts()) {
        the_post();
        $id = get_the_ID();
        $cat = new WPSEO_Primary_Term('category', get_the_ID());
        $category = get_term($cat->get_primary_term());
        $author_id = get_the_author_meta('ID');
        $author_username = get_the_author_meta('display_name');
        $artist_id = get_post_meta($id, 'db_featured_artist_id', true);
        exclude_this_post($id);
        $permalink = get_permalink();
        /* if(is_single()) { ?>
        <div style="position:fixed; margin:0px auto; width:100%;">
        <div class="container">
        <div class="row">
        <div class="col-sm-8">
        <div class="single-header-title"><?php the_title(); ?></div>
        </div>
        </div>
        </div>
        </div> 
        <?php } */
        ?>
<div id="content">
Ejemplo n.º 4
0
function get_top_posts($args = array())
{
    global $post, $exclude_posts;
    $defaults = array('list_post_title' => 'Recent Headlines');
    // merge arguments with defaults && set keys as variables
    $args = array_merge($defaults, $args);
    foreach ($args as $key => $val) {
        ${$key} = $val;
    }
    $args = array('posts_per_page' => 1, 'post_status' => 'publish', 'post__not_in' => $exclude_posts, 'post_type' => 'exclusive');
    $query = new WP_Query($args);
    while ($query->have_posts()) {
        $query->the_post();
        $id = get_the_ID();
        exclude_this_post(1, $id);
        $thumb_caption = '';
        $thumb_id = get_post_thumbnail_id($post->ID);
        $thumb_image = get_posts(array('p' => $thumb_id, 'post_type' => 'attachment'));
        if ($thumb_image && isset($thumb_image[0])) {
            $thumb_caption = $thumb_image[0]->post_excerpt . '</span>';
        }
        ?>

		<article class="top-post">
			<a href="<?php 
        the_permalink();
        ?>
">
				<div class="featured-image" data-src="<?php 
        echo get_thumb_url(700, 700);
        ?>
"></div>
				<div class="wp-caption-text"><?php 
        echo $thumb_caption;
        ?>
</div>
			</a>
			<div class="post-info">
				<div class="col-md-7 left-story">
					<a href="<?php 
        the_permalink();
        ?>
">
						<h1><?php 
        the_title();
        ?>
</h1>
					</a>
					<div class="post-excerpt"><?php 
        the_excerpt();
        ?>
</div>
					<div class="author-title"><h3>written by <?php 
        the_author_posts_link();
        ?>
</h3></div>

				</div>
				<div class="col-md-5 right-story">

					<?php 
        $args = array('posts_per_page' => 4, 'post_status' => 'publish', 'post__not_in' => $exclude_posts, 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC');
        $recent_query = new WP_Query();
        $network_query = $recent_query->posts = network_query_posts($args);
        $post_count = $recent_query->post_count = count($network_query);
        $i = 1;
        while ($recent_query->have_posts()) {
            $recent_query->the_post();
            $blogID = $post->BLOG_ID;
            if ($i == 1) {
                ?>
							<div class="headline-list">
								<h4><?php 
                echo $list_post_title;
                ?>
</h4>
								<ul>
									<?php 
            }
            if ($i >= 1 && $i <= 4) {
                echo '<li>';
                echo list_post($blogID);
                echo '</li>';
            }
            if ($i == 4 || $i == $post_count) {
                ?>
									</ul>
								</div>
								<?php 
                break;
                // so no additional loops once we run out of posts!
            }
            $i++;
        }
        wp_reset_query();
        reset_blog();
        ?>

				</div>
				<div style="clear:both;"></div>
			</div>
		</article>

		<?php 
    }
}