Title: Loop Question
Last modified: August 30, 2016

---

# Loop Question

 *  Resolved [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/)
 * When I click on a tag from the bottom of one of our blog posts, the result is
   our main blog page, not just the articles that are listed under that tag.
 * There’s a file in the theme we’re using called loop.php – is there something 
   you can see that’s interfering with returning just the tag query? Should there
   be another loop file that’s specific for tags? — here’s the code:
 *  `<?php
    $print = 1; if (have_posts()) : while (have_posts()) : the_post(); $
   format = get_post_format($post->ID); if( false === $format ) { $format = ‘standard’;}
   $day = get_the_time(‘j’); $month = get_the_time(‘M’); $year = get_the_time(‘Y’);?
   >
 *  <article class=”post”>
 *  <?php
 *  if( has_post_thumbnail($post->ID) ) { the_post_thumbnail(‘full’, array(‘alt’
   =>$post->post_title)); }
    else { echo ‘<img src=”‘ . get_template_directory_uri(‘
   template_directory’) . ‘/img/default.jpg” />’; }
 *  ?>
 *  <header>
 *  <h3 <?php echo colors(‘h3’);?>><?php echo the_title();?></h3>
 *  </header>
 *  <h4 <?php echo colors(‘h3’);?>><?php echo the_title();?></h4>
 *  <p <?php echo colors(‘p’);?>><?php echo wp_trim_words(get_the_content(),40,’…’);?
   ></p>
 *  <a <?php echo colors(‘a’);?> href=”<?php the_permalink();?>” class=”readmore”
   ><?php _e(‘Read more’,’gym’) ;?> <i class=”entypo-right-open” ></i></a>
 *  <footer>
 *  <span <?php echo colors(‘h1s’);?>><i class=”entypo-pencil” ></i><?php the_author();?
   ></span>
 *  <span <?php echo colors(‘h1s’);?>><i class=”entypo-calendar” ></i><?php echo
   $day;?></span>
 *  <span <?php echo colors(‘h1s’);?>><i class=”entypo-comment” ></i><?php comments_number();?
   ></span>
 *  </footer>
 *  </article>`

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223210)
 * example – [https://www.absolutept.com/electroacupuncture-and-motor-points/](https://www.absolutept.com/electroacupuncture-and-motor-points/)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223222)
 * does your theme have a template **archive.php** or **tag.php**?
 * does your theme use any ‘pre_get_posts’ action in any of the functions files?
 * does the problem persist if your temporarily deactivate **all **plugins?
 * does the problem persist if you temporarily switch to the default theme Twenty
   Fifteen?
 * have you contacted the developer of your theme for help with your question?
    
   [http://codex.wordpress.org/Forum_Welcome#Commercial_Products](http://codex.wordpress.org/Forum_Welcome#Commercial_Products)
 *  Thread Starter [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223240)
 * it does have an archive.php file, no tag.php file
 * no pre_get_posts in the function files
 * still happening after deactivating all plugins
 * works in Twenty Fifteen – not in my theme
 * I have contacted the developer but it’s been 5 days without a response so I thought
   I’d try to find an WP support option
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223311)
 * > it does have an archive.php file
 * what is the full code of **archive.php**?
 * [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223383)
 * thanks for taking a look — here’s the code
 *     ```
       <?php get_header() ?>
           <!-- end Header -->
   
           <!-- begin Content -->
           <section id="news" >
               <!-- begin Sub Header -->
              <?php if(of_get_option('show_banner_blog')){?>
   
               <div class="sub-header" style="<?php echo 'background:url('.of_get_option('blog_banner_image').') no-repeat;'?>">
   
                   <div class="container">
   
                       <div class="row" >
   
                           <ul class="sub-header-container" >
   
                               <li>
   
                                   <h3 <?php echo colors('h3');?> class="title"><?php echo of_get_option('blog_banner_text') ?></h3>
   
                               </li>
   
                               <li>
   
                                   <ul class="custom-breadcrumb" >
   
                                        <li><h6 <?php echo colors('h6');?>><a <?php echo colors('a');?> href="<?php echo home_url();?>"><?php _e('Home','gym') ;?></a></h6></li>
   
                                       <li><i class="separator entypo-play" ></i></li>
   
                                       <li><h6 <?php echo colors('h6');?>><?php echo of_get_option('blog_title')?></h6></li>
   
                                   </ul>
   
                               </li>
   
                           </ul>
   
                       </div>
   
                   </div>
   
               </div>
       <?php } ?> <!-- begin Sub Header -->
   
               <!-- begin News -->
               <article class="article-container">
   
                   <div class="container" >
   
                       <div class="row" >
   
                           <!-- begin Main Colum -->
   
                           <?php if(of_get_option('layer_img') == 'left'){?>
   
                           <aside class="col-sm-3 sidebar">
   
                               <?php get_sidebar() ?>
   
                           </aside>
   
                           <?php }?>
   
                           <div class="<?php if(of_get_option('layer_img') == 'none'){echo 'col-sm-12';}else{echo 'col-sm-9';}?>">
   
                               <h2 <?php echo colors('h2');?> class="article-title" ><?php echo of_get_option('blog_title')?></h2>
   
                               <span <?php echo colors('h1s');?> class="line" >
   
                                   <span <?php echo colors('h1s');?> class="sub-line" ></span>
   
                               </span>
   
                               <section class="posts">
   
                               <?php
   
                               $paginar=1;
                               $page = isset($_GET['page']) ? $_GET['page'] : 1;
   
                               $args = array(
                                   'paged' => $page,
                                   'post_status' => 'publish',
                                   'order_by' => 'date',
                               );
   
                               query_posts($args);
                               while (have_posts()) {
                                 the_post();
   
                                 $day = get_the_time('F j, Y');
   
                                 $cate = get_the_category(get_the_id());
                     foreach($cate as $k){
                     }
                              ?>
   
                                   <article class="post">
   
                                       <?php the_post_thumbnail();?>
   
                                       <header>
   
                                           <h3 <?php echo colors('h3');?>><?php echo the_title();?></h3>
   
                                       </header>
   
                                       <h4 <?php echo colors('h4');?>><?php echo the_title();?></h4>
   
                                       <p <?php echo colors('p');?>><?php echo wp_trim_words(get_the_content(),40,'...');?></p>
   
                                       <a <?php echo colors('a');?> href="<?php the_permalink();?>" class="readmore"><?php _e('Read more','gym') ;?><i class="entypo-right-open" ></i></a>
   
                                       <footer>
   
                                           <span <?php echo colors('h1s');?>><i class="entypo-pencil" ></i><?php the_author();?></span>
   
                                           <span <?php echo colors('h1s');?>><i class="entypo-calendar" ></i><?php echo $day;?></span>
   
                                           <span <?php echo colors('h1s');?>><i class="entypo-comment" ></i><?php comments_number();?></span>
   
                                       </footer>
   
                                   </article>
   
                                  <?php  } ?>
   
                                   <aside>
   
                                       <ul class="pagination">
   
                                          <?php
       if ($paginar == '1') {
          gym_pagination();
       }
       else
       {
        next_posts_link('&larr; '.'Older posts', 'gym' );
       previous_posts_link('Newer posts'.' &rarr;', 'gym' );
       }
       ?>
   
       </ul>
   
                                   </aside>
   
                               </section>
   
                           </div>
                           <!-- end Main Colum -->
   
                           <!-- begin Sidebar -->
                           <?php if(of_get_option('layer_img') == 'right'){ ?>
   
                           <aside class="col-sm-3 sidebar">
                               <?php get_sidebar() ?>
                           </aside>
                           <?php }?>
                           <!-- end Sidebar -->
                       </div>
                   </div>
               </article>
               <!-- end News -->
   
           </section>
           <!-- end Content -->
   
       <?php get_footer() ?>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223384)
 * in the code of **archive.php**, this custom query is messing with the output:
 *     ```
       $args = array(
                                   'paged' => $page,
                                   'post_status' => 'publish',
                                   'order_by' => 'date',
                               );
   
                               query_posts($args);
       ```
   
 * remove that section.
 * if you need or want to sort the archive output in any way, consider to use the`'
   pre_get_posts'` method [http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)–
   do not add custom queries before the loop in any of the default templates.
 *  Thread Starter [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223427)
 * thanks for the information =)
 *  Thread Starter [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * (@kellyalan)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223512)
 * What I did is change the name of the archive.php file to tag.php – removed that
   code you said was interfering with the output, uploaded the tag.php file to my
   child theme
 * seems to be working
 * I appreciate the help

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Loop Question’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [kellyalan](https://wordpress.org/support/users/kellyalan/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/loop-question-4/#post-6223512)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
