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.