function single_artist_widget($id) { $blogID = get_blog_by_name('artists'); min_switch_to_blog($blogID); $artist = get_post($id); $thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id($id), array(300, 300))[0]; $post_meta = get_post_custom($id); // assign all columns to variable $artist_columns = artist_columns(); // in case value isn't set in database, set required variables to '' foreach ($artist_columns as $column) { ${$column} = ''; } // assign all fields foreach ($post_meta as $key => $meta) { if (array_key_exists($key, array_flip($artist_columns))) { // if we want this key if (isset($key) && !empty($key)) { ${$key} = trim($meta[0]); } else { ${$key} = ''; } } } reset_blog(); $tour_dates = json_decode($artist_tour_dates); ?> <div class="single-artist-widget"> <?php if ($artist_sponsor != '') { ?> <div class="artist-sponsor">Presented by <img src="<?php echo $artist_sponsor; ?> " /></div> <?php } ?> <h2>Featured Artist <span><?php echo $artist_name; ?> </span></h2> <div class="artist-image" style="background-image:url('<?php echo $thumb_url; ?> ');"></div> <ul class="social"> <?php if ($artist_instagram != '') { echo '<li class="instagram">' . social_media('instagram', $artist_instagram) . '</li>'; } ?> <?php if ($artist_twitter != '') { echo '<li class="twitter">' . social_media('twitter', $artist_twitter) . '</li>'; } ?> <?php if ($artist_soundcloud != '') { echo '<li class="soundcloud">' . social_media('soundcloud', $artist_soundcloud) . '</li>'; } ?> </ul> <?php if (isset($tour_dates) && isset($tour_dates->resultsPage) && isset($tour_dates->resultsPage->results) && isset($tour_dates->resultsPage->results->event) && count($tour_dates->resultsPage->results->event) > 0) { ?> <h4>Upcoming Tour Dates</h4> <ul class="tour-dates"> <?php $i = 0; foreach ($tour_dates->resultsPage->results->event as $date) { $venue = $date->venue->displayName; // stripping separately just in case $display = strstr($date->displayName, ' (', true); $display = strstr($display, ' at ', true); $permalink = $date->uri; if ($display == '') { continue; } $start = DateTime::createFromFormat('Y-m-d', $date->start->date); $start_month = $start->format('M'); $start_day = $start->format('d'); echo '<li>'; echo '<div class="date"><div class="month">' . $start_month . '</div>' . $start_day . '</div>'; echo '<div class="details">'; echo '<a href="' . $permalink . '">' . $display . '</a>'; echo '<div class="location">at ' . $venue . '</div>'; echo '</div>'; echo '</li>'; $i++; if ($i > 4) { break; } } ?> </ul> <?php if ($i > 4) { ?> <a class="view-all" href="http://www.songkick.com/artists/<?php echo $artist_id; ?> " target="_blank">View All Tour Dates</a> <?php } ?> <?php } ?> </div> <?php }
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(); }
function get_fresh_new_tracks($args = array()) { global $exclude_posts; $defaults = array('offset' => 0, 'posts_per_page' => 20, 'sticky_wrapper' => true); // merge arguments with defaults && set keys as variables $args = array_merge($defaults, $args); foreach ($args as $key => $val) { ${$key} = $val; } $blogID = get_blog_by_name('freshnewtracks'); switch_to_blog($blogID); $exclude = $exclude_posts[$blogID]; $args = array('posts_per_page' => $posts_per_page, 'post_status' => 'publish', 'post__not_in' => $exclude, 'post_type' => 'tracks'); $rank = 1 + $offset; $open = false; // whether or not to close div $query = new WP_Query($args); while ($query->have_posts()) { $query->the_post(); if ($sticky_wrapper && $rank == 15) { $open = true; echo '<div class="fnt-sticky-wrapper">'; } echo fresh_new_track($blogID, $rank); $rank++; } if ($sticky_wrapper && $open) { echo '</div>'; } reset_blog(); }