/**
 * @param $post_id int ID of the post (or, null if in The Loop)
 * @return array List of of zones that the given post is in
 */
function z_get_post_zones($post_id = 0)
{
    $post_id = z_get_loop_post_id_or_default($post_id);
    return z_get_zoninator()->get_zones_for_post($post_id);
}
Example #2
0
 /**
  * Use a plugin to get related posts, or fall back to
  * simply fetching some posts from the same category.
  */
 public static function get_related_posts()
 {
     $post = get_post();
     $posts_per_page = apply_filters('semicolon_related_posts_per_page', 4);
     // Support for the Zone Manager (Zoninator) plugin
     if (function_exists('z_get_zoninator')) {
         // Allow plugins and child themes to define their own zones or use defaults.
         $zones = apply_filters('semicolon_related_posts_zones', false, $post->ID);
         if (!is_array($zones)) {
             $zones = array('related-posts');
             $categories = wp_get_object_terms($post->ID, array('category'), array('fields' => 'slugs'));
             foreach ($categories as $slug) {
                 $zones[] = 'related-posts-' . $slug;
             }
             $zones = array_reverse($zones);
         }
         foreach ($zones as $zone) {
             $query = z_get_zoninator()->get_zone_query($zone, apply_filters('semicolon_related_posts_query_args', array('posts_per_page' => $posts_per_page, 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => true)));
             if ($query->have_posts()) {
                 return $query;
             }
         }
     }
     // Support for the Yet Another Related Posts Plugin
     if (function_exists('yarpp_get_related')) {
         $related = yarpp_get_related(array('limit' => $posts_per_page), $post->ID);
         $args = array('post__in' => wp_list_pluck($related, 'ID'), 'posts_per_page' => $posts_per_page, 'ignore_sticky_posts' => true, 'post__not_in' => array($post->ID));
         $args = apply_filters('semicolon_related_posts_query_args', $args);
         return new WP_Query($args);
     }
     $args = array('posts_per_page' => $posts_per_page, 'ignore_sticky_posts' => true, 'post__not_in' => array($post->ID));
     // Get posts from the same category.
     $categories = get_the_category();
     if (!empty($categories)) {
         $category = array_shift($categories);
         $args['tax_query'] = array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => $category->term_id));
     }
     $args = apply_filters('semicolon_related_posts_query_args', $args);
     return new WP_Query($args);
 }