Post Archives
Easy Query Pro makes it easy to fetch and display post archive content on WordPress archive pages by simply adding archive=”true” to the core shortcode.
Example Shortcode[easy_query archive="true"post_type="post"]
With archive set in a shortcode, Easy Query will automatically detect the current archive type and build the perfect query on the server side based on the type.
Archive Types
The following archive types are currently supported with the archives integration.
- Taxonomy
- Category
- Tag
- Author
- Date (year, month, day)
- Post Type Archives
Template Example
The following code sample is a complete archive.php template that generates the page title for each archive type followed by the Easy Query shortcode.
You can separate archives into unique templates (category.php, tag.php etc) if you wish – the archive integration works in all supported archive templates.
<?php
// archive.php
get_header();
?>
<div class="container">
<?php
if(is_tax()){ // Taxonomy Archives
$queried_object = get_queried_object();
echo '<h1>'.$queried_object->name.'</h1>';
}
if(is_category()){ // Category Archives
$cat = get_query_var('cat');
$category = get_category ($cat);
echo '<h1>'. $category->cat_name .'</h1>';
}
if(is_tag()){ // Tag Archives
$tag = get_query_var('tag');
echo '<h1>'. single_tag_title('',false) .'</h1>';
}
if(is_author()){ // Author Archives
echo '<h1>'. get_the_author_meta('display_name') .'</h1>';
}
if(is_year()){ // Year Archives
echo '<h1>'. the_date('Y') .'</h1>';
}
if(is_month()){ // Month Archives
echo '<h1>'. the_date('F, Y') .'</h1>';
}
if(is_day()){ // Day Archives
echo '<h1>'. the_date('F jS, Y') .'</h1>';
}
?>
<?php echo do_shortcode('[easy_query archive="true" post_type="post"]'); ?>
</div>
<?php get_footer(); ?>
PHPNote: When using the archive integration, do not set additional query shortcode parameters other than posts_per_page and/or post_type – Easy Query Pro automatically creates the query for you based on the current archive page and other parameters may cause unexpected consequences.