I have a page that reads the variable ( a single letter) from the url. The page then displays custom posts assigned to that letter. (The letter is a custom field)
The problem is that the template assigned to the page is not doing the final rendering of the page.
The template contains the following code:
<?php $letter = $_GET['letter']; if ($letter=="") $letter = 'A';?><?php /*If there is no value returned then the loop defaults to searching for items beginning with 'A'*/ ?> <h1>Glossary Items Listed Under Letter "<?php echo $letter ?>"</h1> <?php /*This needs to be outside of the loop*/?> <?php $loop = new WP_Query( array( 'post_type' => 'glossary', 'meta_key'=> 'first-letter', 'meta_value' => $letter, 'posts_per_page' => 10 ) ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post();?> <div class="glossarybody"> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> </div> <?php endwhile; ?>
When that code is on the page the page displays the correct results ( a list of titles) but using the plugin ‘reveal templates’ I see that the page is being rendered with ‘page.php’.
The correct template should be glossary-terms.php (I’ve tried using the filename terms.php in case the word glossary, the name of the custom post type involved, was causing a problem .)
If I remove the above code so that I’m left with a more or less static page that has some html, header, footer and sidebar, then the page renders using the correct template.
This suggests that something in the operation of WordPress is causing the template to change in the execution of the initial template.
I’d appreciate any pointers on what might be wrong with my setup and how to get the correct template to render the page.
- The topic ‘Template changes based on template code??’ is closed to new replies.