Auto-populate Grid for Blog Pages within “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 inside The Loop. for an "outside The Loop" example, Click Here

First you need to find the theme folder holding the template files needed. The following process works with every theme template file using the WordPress loop. We will be using the loop because this way manual post ordering, number of posts per page, sticky post positioning, all query data, filter/actions on post, etc. keep intact.

So you could use it on the following files (find out more about the hierarchy here):

  • index.php
  • home.php
  • category.php
  • archive.php
  • author.php
  • archive-(postype).php
  • taxonomy.php
  • date.php
  • tag.php
  • search.php

Now you need to locate the loop inside the chosen file. The loop starts with the following line:

Please place the declaration of our post array before this line so that it is reading:

Now look for the end of the loop’s “endwhile;” and exchange all code in between with this single line:

This single line will populate the array with all queried post IDs.

Next step is to copy the shortcode of your prefered Essential Post Grid right after the loops end, put in the post array and echo it out with executing the shortcode before:

Here is the example source embeded into the index.php of the “Twenty Fifteen” standard theme:

Remember to coordinate the WordPress “Post per Page” setting with the pagination setting of Essential Grid.

If you want to use the Essential Grid included pagination only please set the “Post per Page” in the Reading Settings to an abnormal huge number like 99999. This will make the theme’s default pagination disappear.

If you want to change the number of posts per page depending on the post type or other conditionals you can use the “pre_get_posts” filter:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts