Exemplo n.º 1
0
function get_standard_posts(array $args)
{
    global $exclude_posts;
    global $query_string;
    $defaults = array('category' => 0, 'author' => 0, 'offset' => 0, 's' => '', 'full_offset' => 1, 'show_ads' => 0);
    // merge arguments with defaults
    $args = array_merge($defaults, $args);
    foreach ($args as $key => $val) {
        ${$key} = $val;
        // set up each key as a variable
    }
    $search_query = array();
    $cat_object = get_category_by_slug('featured');
    $featured_cat = $cat_object->term_id;
    $ad_count = 0;
    if ($show_ads == 1) {
        $ads = get_standard_ads();
        $ad_count = count($ads);
    }
    if ($show_ads == 1 && $ad_count > 0) {
        $i = 1;
        // first post
        echo '<div class="row">';
        echo '<div class="col-sm-8 standard-post">';
        if ($show_ads == 1 && array_key_exists($i, $ads)) {
            echo standard_ad($ads[$i]);
        } else {
            $featured_args = array('posts_per_page' => 1, 'cat' => $featured_cat, 'post_status' => 'publish', 'post__not_in' => $exclude_posts, 'post_type' => 'post');
            $featured_query = new WP_Query($featured_args);
            while ($featured_query->have_posts()) {
                $featured_query->the_post();
                echo spotlight_post();
            }
            $full_offset++;
            // increase offset counter
        }
        echo '</div>';
        $i++;
        // move to post #2
        $posts_per_page = 5;
        if ($show_ads == 1) {
            $posts_per_page = posts_to_query_after_ads(array(2, 3, 4, 5, 6), $ads);
            // spots 2 - 6
        }
        $x = $i;
        while ($i < 6) {
            // (2 - 6)
            if ($show_ads == 1) {
                check_ads($i, $ads);
                // check and display ads
            }
            if ($posts_per_page > 0) {
                // if there is more than just ads
                $args = array('posts_per_page' => $posts_per_page, 'cat' => $category . ', -' . $featured_cat, 'post_status' => 'publish', 'offset' => $offset, 'author' => $author, 'post_type' => 'post', 'post__not_in' => $exclude_posts);
                $post_query = new WP_Query($args);
                while ($post_query->have_posts()) {
                    $post_query->the_post();
                    echo '<div class="col-sm-4 standard-post">';
                    echo classic_post();
                    echo '</div>';
                    $i++;
                    if ($show_ads == 1) {
                        check_ads($i, $ads);
                        // check and display ads
                    }
                }
            }
            if ($x == $i) {
                return;
            }
        }
        // i should == 7
        echo '<div class="col-sm-8 standard-post">';
        if ($show_ads == 1 && array_key_exists($i, $ads)) {
            echo standard_ad($ads[$i]);
        } else {
            $featured_args = array('posts_per_page' => 1, 'cat' => $featured_cat, 'post_type' => 'post', 'post_status' => 'publish', 'post__not_in' => $exclude_posts);
            $featured_query = new WP_Query($featured_args);
            while ($featured_query->have_posts()) {
                $featured_query->the_post();
                echo spotlight_post();
            }
            $full_offset++;
            // increase offset counter
        }
        echo '</div>';
        $i++;
        // move to post #2
        $posts_per_page = 3;
        if ($show_ads == 1) {
            $posts_per_page = posts_to_query_after_ads(array(8, 9, 10), $ads);
            // spots 2 - 6
        }
        $x = $i;
        while ($i < 11) {
            // (2 - 6)
            if ($show_ads == 1) {
                check_ads($i, $ads);
                // check and display ads
            }
            if ($posts_per_page > 0) {
                // if there is more than just ads
                $args = array('posts_per_page' => $posts_per_page, 'cat' => '-' . $featured_cat, 'post_status' => 'publish', 'offset' => $offset, 'post_type' => 'post', 'author' => $author, 'post__not_in' => $exclude_posts);
                $post_query = new WP_Query($args);
                while ($post_query->have_posts()) {
                    $post_query->the_post();
                    echo '<div class="col-sm-4 standard-post">';
                    echo classic_post();
                    echo '</div>';
                    $i++;
                    if ($show_ads == 1) {
                        check_ads($i, $ads);
                        // check and display ads
                    }
                }
            }
            if ($x == $i) {
                return;
            }
        }
        if ($i > 1) {
            echo '</div>';
        }
        if ($i == 1) {
            echo 'That is all!';
        }
        return;
    }
    // IF THERE ARE NO ADS: this loop is smaller amd faster
    $i = $x = 1;
    // x is used to determine if there are posts
    echo '<div class="row">';
    $posts_per_page = 8;
    // show 8 posts as default
    $category__and = array();
    if ($category == 0) {
        $category__and == array($featured_cat);
    } else {
        $category__and == array($category, $featured_cat);
    }
    // i == 1;
    $featured_args = array('posts_per_page' => 2, 'category__and' => $category__and, 's' => $s, 'post_status' => 'publish', 'post_type' => 'post', 'post__not_in' => $exclude_posts);
    $featured_args = array_merge($search_query, $featured_args);
    // merge potential search
    $featured_query = new WP_Query($featured_args);
    if (!$featured_query->have_posts()) {
        $posts_per_page = 12;
    }
    // if there are no posts, show 12 classic
    while ($featured_query->have_posts()) {
        $featured_query->the_post();
        echo '<div class="col-sm-8 standard-post">';
        echo spotlight_post();
        echo '</div>';
        $x++;
        if ($featured_query->current_post + 1 >= $featured_query->post_count) {
            $posts_per_page = 10;
        }
        // if there is not another featured post, show 10 classic
        break;
    }
    //$full_offset++; // increase offset counter
    $i++;
    $args = array('posts_per_page' => $posts_per_page, 'cat' => $category . ', -' . $featured_cat, 'post_status' => 'publish', 'offset' => $offset, 's' => $s, 'post_type' => 'post', 'author' => $author, 'post__not_in' => $exclude_posts);
    $args = array_merge($search_query, $args);
    // merge potential search
    $post_query = new WP_Query($args);
    while ($post_query->have_posts()) {
        $post_query->the_post();
        echo '<div class="col-sm-4 standard-post">';
        echo classic_post();
        echo '</div>';
        $x++;
        $i++;
        if ($i == 7 && $posts_per_page == 8) {
            $featured_args = array('posts_per_page' => 1, 'category__and' => $category__and, 'post_status' => 'publish', 's' => $s, 'post_type' => 'post', 'post__not_in' => $exclude_posts);
            $featured_args = array_merge($search_query, $featured_args);
            // merge potential search
            $featured_query = new WP_Query($featured_args);
            while ($featured_query->have_posts()) {
                $featured_query->the_post();
                echo '<div class="col-sm-8 standard-post">';
                echo spotlight_post();
                echo '</div>';
            }
            $full_offset++;
            // increase offset counter
        }
    }
    echo '</div>';
    if ($x == 1) {
        echo 'That is all!';
    }
}
Exemplo n.º 2
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();
}
Exemplo n.º 3
0
    echo '</div>';
}
$args = array('posts_per_page' => 1, 'cat' => $spotlight_left, 'post_status' => 'publish');
$query = new WP_Query($args);
while ($query->have_posts()) {
    $query->the_post();
    echo '<div class="col-md-3 spotlight-posts">';
    echo spotlight_post();
    echo '</div>';
}
$args = array('posts_per_page' => 1, 'cat' => $spotlight_right, 'post_status' => 'publish');
$query = new WP_Query($args);
while ($query->have_posts()) {
    $query->the_post();
    echo '<div class="col-md-3 spotlight-posts">';
    echo spotlight_post();
    echo '</div>';
}
?>

</div>

<div class="container main">
	<div class="row">
		<div class="col-md-12">
			<?php 
get_ad('banner');
?>
			<?php 
global $exclude_posts;
?>