Created
October 10, 2012 12:55
-
-
Save Kevinlearynet/3865441 to your computer and use it in GitHub Desktop.
Curated Content Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template Name: Around The Web | |
| * | |
| * The template for displaying a curated resources Archive. | |
| * | |
| * Learn more: http://codex.wordpress.org/Template_Hierarchy | |
| * | |
| * @package _s | |
| * @since _s 1.0 | |
| */ | |
| get_header(); | |
| // Custom loop | |
| $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; | |
| $custom_loop_args = array( | |
| 'post_type' => 'post', | |
| 'post_status' => 'publish', | |
| 'ignore_sticky_posts' => 1, | |
| 'paged' => $paged, | |
| 'post_type' => array('videos', 'post'), | |
| 'meta_query' => array( | |
| 'relation' => 'OR', | |
| array( | |
| 'key' => 'article_source', | |
| 'compare' => '!=', | |
| 'value' => '' | |
| ), | |
| array( | |
| 'key' => 'article_link', | |
| 'compare' => '!=', | |
| 'value' => '' | |
| ) | |
| ) | |
| ); | |
| // Check the current zone | |
| global $current_zone; | |
| // Check for category match to current zone | |
| if ( term_exists($current_zone, 'category') ) { | |
| $term = get_term_by('name', $current_zone, 'category'); | |
| $custom_loop_args['cat'] = $term->term_id; | |
| } | |
| // Check for category match to current zone | |
| elseif ( term_exists($current_zone, 'post_tag') ) { | |
| $term = get_term_by('name', $current_zone, 'post_tag'); | |
| $custom_loop_args['tag_id'] = $term->term_id; | |
| } | |
| // Create unique identifier for caching | |
| $cache_id = ( isset($term) ) ? '_term-' . $term->term_id : '_main'; | |
| // Run query or get transient cache | |
| if ( ( $custom_loop = get_transient( "curated_wpquery$cache_id" ) ) === false ) { | |
| // It wasn't there, so regenerate the data and save the transient | |
| $custom_loop = new WP_Query( $custom_loop_args ); | |
| set_transient( "curated_wpquery$cache_id", $custom_loop, ( 60 * 60 * 1 ) ); | |
| } | |
| ?> | |
| <section id="primary" class="content-area"> | |
| <div id="content" class="site-content" role="main"> | |
| <?php if ( $custom_loop->have_posts() ) : ?> | |
| <header class="page-header"> | |
| <h1 class="archive-title"><?php the_title(); ?></h1> | |
| </header><!-- .page-header --> | |
| <?php while ( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?> | |
| <?php | |
| /** | |
| * Include the Post-Format-specific template for the content. | |
| * If you want to overload this in a child theme then include a file | |
| * called content-___.php (where ___ is the Post Format name) and that will be used instead. | |
| */ | |
| get_template_part( 'content' ); | |
| ?> | |
| <?php endwhile; wp_reset_postdata(); ?> | |
| <?php _s_content_nav( 'nav-below', $custom_loop->max_num_pages ); ?> | |
| <?php else : ?> | |
| <?php get_template_part( 'no-results', 'archive' ); ?> | |
| <?php endif; ?> | |
| </div><!-- #content .site-content --> | |
| </section><!-- #primary .content-area --> | |
| <?php get_sidebar(); ?> | |
| <?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment