You’re limiting your query via posts_per_page
to five results, to get all possible results use -1
. Don’t use $wp_query
as variable name, as it is associated to a global
variable with the same name, which can lead to interferences. But that said, you absolutely don’t need a custom query in your tag.php
. You are already querying for a specific tag, with ?tag=abc
or /tag/abc
in your URL. WordPress catches that and selects the correct template, and limits the query to that tag. There is a hierarchy on how tag template (codex page; read it for more information) files get selected:
- tag-slug.php
- tag-id.php
- tag.php
- archive.php
- index.php
If available then the order is first to fifth, if not WordPress is looking for the next one. Additionally I would recommend to give the Theme Developer Handbook a good read, especially the section about Template Files. In the end you just need a template file to fit your needs. Below a exemplary template file.
<?php
/**
* The template for displaying tag pages.
*
* @package WordPress
* @subpackage Theme
*/
?>
<?php get_header(); ?>
<!-- tag | start -->
<div class="row">
<div class="col-xs-12">
<?php the_archive_title( '<div class="page-header"><h1 class="page-title">', '</h1></div>' ); ?>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<?php if ( have_posts() ) : ?>
<?php $description = get_the_archive_description(); ?>
<?php if ( ! empty( $description ) ) :?>
<div class="archive-description">
<?php echo $description; ?>
</div>
<?php endif; ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- tag loop | start -->
<div id="content" <?php post_class(); ?>>
<div class="row">
<div class="col-xs-12">
<?php the_title( '<div class="post-header"><h2 class="post-title">', '</h2></div>' ); ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div><!-- .entry-thumbnail -->
<?php endif; ?>
<div class="entry-content">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</div>
</div>
</div><!-- #content -->
<!-- tag loop | end -->
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<!-- tag | end -->
<?php get_footer(); ?>