Skip to content

Instantly share code, notes, and snippets.

@kellymears
Created July 24, 2012 14:16
Show Gist options
  • Save kellymears/3170151 to your computer and use it in GitHub Desktop.
Save kellymears/3170151 to your computer and use it in GitHub Desktop.
Post Archive Factory
<?php
/**
* Template Name: Archive Query
* Description: Retrieves Posts
*
* @package Toolbox
* @since Toolbox 0.1
*/
get_header(); ?>
<!-- Body -->
<div class="container main-container">
<div class="row">
<div class="span9">
<header class="entry-header">
<h1 class="entry-title" style="margin-bottom: 10px;"><?php the_title(); ?></h1>
</header>
<?php
$archive_post_type = get_post_meta($post->ID, 'archive_query_type', true);
$archive_meta_key = get_post_meta($post->ID, 'archive_meta_key', true);
$archive_meta_value = get_post_meta($post->ID, 'archive_meta_value', true);
$archive_showposts = get_post_meta($post->ID, 'archive_showposts', true);
if($archive_post_type != '') :
$new_query = new WP_Query();
$new_query->query('post_type='.$archive_post_type.'
&showposts='.$archive_showposts.'
&paged='.$paged.'
&meta_key='.$archive_meta_key.'
&meta_value='.$archive_meta_value.''); ?>
<?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<h3><?php the_field('date'); ?></h3>
<p><?php the_field('excerpt'); ?></p>
<p><a href="<?php echo get_permalink(); ?>" class="btn btn-primary">Read more</a></p>
<hr>
<?php endwhile; ?>
<?php next_posts_link('&laquo; Older Entries', $new_query->max_num_pages); ?>
<?php previous_posts_link('Newer Entries &raquo;'); ?>
<?php endif; ?>
</div><!-- /.span8 -->
<?php get_sidebar(); ?>
</div><!-- /.row -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment