Archives
Ajax Load More makes it easy to fetch and display archive content on WordPress archive and search pages by simply adding archive=”true” to the core Ajax Load More shortcode.
Example Shortcode[ajax_load_more archive="true" post_type="post" posts_per_page="8"]
With archive set in a shortcode, Ajax Load More will automatically detect the current archive content type and build the perfect query on the server side.
Archive Types
The following archive types are currently supported with the archives integration.
- Taxonomy
- Category
- Tag
- Author
- Date (year, month, day)
- Post Type Archives
- Search
Template Example
The following code sample is a complete archive.php template that generates the page title for each archive type followed by the Ajax Load More 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>';
}
echo do_shortcode( '[ajax_load_more 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 post_type. Ajax Load More automatically creates the query based on the current archive page and other parameters may cause unexpected consequences.