Auto-populate Grid for Blog Pages Outside “The Loop” (advanced)

If you want to use Essential Grid for the Blog, Category, Archive, Tags, Author, Search pages of your theme, the following code snippet can be added to your corresponding theme files.

This example is for adding the custom code outside The Loop. For an “inside The Loop” example, Click Here

if(is_tag()) $my_posts = get_posts(array('tag' => get_query_var('tag')));
else if(is_author()) $my_posts = get_posts(array('author' => get_query_var('author')));
else if(is_date()) $my_posts = get_posts(array('m' => get_query_var('m')));
else $my_posts = get_posts(array('cat' => get_query_var('cat')));
 
$my_post_ids = array();
 
foreach($my_posts as $post) {
   array_push( $my_post_ids, $post -> ID );
}
 
echo do_shortcode(''); 

Example of the snippet added to the TwentyFifteen theme’s “archives.php” file.

This code can also be added to another one of your theme’s php files, such as “category.php”, “index.php”, etc.

Auto-populate Grid for Blog Pages Outside “The Loop” (advanced)

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!

[tp_popular title="Popular Grids" regex="(grids|template_library)" count=3]

Newsletter

Join over 25.000 others on the Essential Grid and Slider Revolution email list to get access to the latest news and exclusive content.