Any tag pagination page (except the 1st one) displays index.php

custom theme file structure

Created my first custom theme from scratch and I’m trying to do a listing of all posts with the same tag.

In tag.php I display all posts with that specific tag via a WP_Query and I’m trying to implement the pagination for that listing (using paginate_links() ). Page links seem to be outputted correctly. Also the first page looks good.

What I don’t understand is that when I go on the next tag page (or to any of the page links outputted in my tag.php; eg. http://127.0.0.1/wp_site/tag/test_tag/page/2/ ) the content from index.php is displayed.

What am I actually missing for displaying the subsequent tag pages correctly?

I have the following code in functions.php:

function nllTagFilter($query) {
    if ($query->is_main_query()) {
        if ($query->is_tag) {
            $post_types = get_post_types();
            $query->set('post_type', $post_types);
        }
    }
}

add_action('pre_get_posts','nllTagFilter');

This is my theme’s file-structure so far:

Read more here:: Any tag pagination page (except the 1st one) displays index.php

Leave a Reply

Your email address will not be published. Required fields are marked *