Title: Load custom category template?
Last modified: August 19, 2016

---

# Load custom category template?

 *  [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/)
 * My last post got accidentaly closed somehow. Here it is again:
 * Hello. I have made my own integrated theme (Ztheme), with the templates in ../
   themes/ztheme – but the ‘index.php’ is moved to the root, because it’s my main
   page.
 * Anyway, I want a specific category to show up in a modified template, so I make
   it and name it category-15.php, and upload it to my Ztheme folder. It refuses
   to work. I’ve also tried to upload ‘archive.phph’ and ‘category.php’ – but it
   still uses ‘index.php’.
 * What could be the solution here?
 * Even though I change theme back to the default, my categories still show up using
   the ‘index.php’-page rather than the default theme’s ‘archive.php’ as it should
   according to the template hierarchy.
 * How can I force it to use a certain template for say, Category 15? It just does
   not work.
    I would be very grateful for help.
 * [my page:](http://zetterstrand.com)
 * my index code:
 *     ```
       <?php
       /**
        * @package WordPress
        * @subpackage Ztheme
        */
       require('./eventz/wp-blog-header.php');
       get_header();
       ?>
   
       <div id="mainContent">
   
           <div class="frontpage">
                   (here's some static images and text that gets displayed on all pages)
           </div>
                     <!--End of frontpage-->
   
           <div class="blogcontent">
           <!--excludes posts from category 15 (articles) on the mainpage-->   <?php if ( is_home() ) {query_posts($query_string . '&cat=-15'); } ?>
   
       <?php if (have_posts()) : ?>
   
       		<?php while (have_posts()) : the_post(); ?>
   
       			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
       				 <?php the_time('Y-m-d') ?> <!-- by <?php the_author() ?> -->&nbsp;<img src="http://zetterstrand.com/logos/squareFF6600_2.gif" alt="sq" width="20" height="27" />
       				<h2><a style="text-decoration:none; color: #333333;" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
   
       				<div class="entry">
       					<?php the_content('Read the rest of this entry &raquo;'); ?>
       				</div>
   
       				<!--<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> --> Posted in <?php the_category(', ') ?> <!--| <?php edit_post_link('Edit', '', ' | '); ?>  			<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>-->
       			</div>
   
       		<?php endwhile; ?>
   
       		<div class="navigation">
       			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
       			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
       		</div>
   
       	<?php else : ?>
   
       		<h2 class="center">Not Found</h2>
       		<p class="center">Sorry, but you are looking for something that isn't here.</p>
       		<?php get_search_form(); ?>
   
       	<?php endif; ?>
   
           </div> <!-- end #blogcontent -->         
   
         <!-- end #mainContent -->
       </div>
   
       <div class="sidebar">
   
       Blog categories: <?php wp_list_categories('hierarchical=0&title_li=');    ?>
   
       </div>
   
       <div id="rss">
        <span class="styleKZsmall">Subscribe to posts [RSS]</span> <a title="RSS Feed of Posts" href="<?php bloginfo('rss2_url'); ?> "><img src="/logos/rss.png" alt="Subscribe to posts [RSS]" width="16" height="16" vspace="0" border="0"/>
       </div>
   
       <?php get_footer(); ?>
       ```
   

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

 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378517)
 * You have to give it a template name. The following code goes at the top of the
   page, where you call the header.
 *     ```
       <?
       /*
       Template Name: Index-15
       */
   
       get_header();
       ?>
       ```
   
 * and then ensure that the page is assigned to that Template in the admin panel.
   To do this click ‘Pages’, select the page you wish to use this template and look
   on the ‘Attributes’ box. The Template selection is made there.
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378520)
 * Ah, thanks – so you mean my code should look like this in the beginning?
 *     ```
       <?php
       /**
        * @package WordPress
        * @subpackage Ztheme
        */
       /*
       Template Name: Ztheme
       */
       require('./eventz/wp-blog-header.php');
       get_header();
       ?>
       ```
   
 * ?
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378521)
 * Yes, and then the template will appear in the drop down menu when you go to edit
   the Page.
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378522)
 * Ah, but there is no “page” to edit.
    I just want wordpress to use the template“
   category-15.php” when I choose to click on the category 15. ([according to this](http://codex.wordpress.org/Category_Templates#What_Template_File_is_Used.3F))
   The thing is, that instead of using my “category-15.php” or even “category.php”
   or “archive.php” – it is using my main page “index.php” as a template.
 * Or did I misunderstand you?
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378526)
 * EDIT:
    This might be a clue.
 * when I add
 *     ```
       define('WP_USE_THEMES', true);
       ```
   
 * to the root index.php, all category pages show up, using the archive.php template!(
   if you go to the category url like [http://mypage.com/category/dogfood](http://mypage.com/category/dogfood))
 * BUT – now the index.php does not work by itself, so going to [http://mypage.com](http://mypage.com)
   results in a redirect error…..
 * now what?
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378537)
 * Are you trying to display a single post or a list of posts in a Category? If 
   it is the latter, then all I do is create a dummy page (Category 15) and set 
   that to use the template. You can then call that page, but your template doesn’t
   have to display any of the information contained in the post.
 * Also, you can check your Reading settings to ensure that you have the correct
   pages selected are your homepage there.
 * For example, my Posts Page is set to a Page called ‘News’, which uses the index.
   php template but does not draw any information from the Page, so it’s effectivly
   just a dummy – while my Front Page is set to ‘Home’, which uses an entirely different
   template called ‘Homepage’.
 * I may be missing the mark with what you are trying to achieve, but I remember
   when I first started I was trying to over complicate it and alot of the time 
   it was just unnecessary.
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378538)
 * Having re-read I may now be with you –
 * In my index.php I use –
 *     ```
       <?
       /*
       Template Name: Index
       */
       if($_GET['cat'] != ''){
       	$typeOf = 'cat';
                $cat =  $_GET['cat'];
       }
       if($_GET['tag'] != ''){
       	$typeOf = 'tag';
                $tag =  $_GET['tag'];
       }
       if($_GET['contact'] != ''){
       	$typeOf = 'contact';
                $contact =  $_GET['contact'];
       }
       get_header();
       ?>
       ```
   
 * Then, befor I write the page I query the Posts to ensure only the correct posts
   are displayed –
 *     ```
       <? query_posts(array('cat' => $cat, 'posts_per_page' => 10, 'paged' => $_GET['paged'], 'tag' => tag, 'contact' => contact));
   
       if(have_posts()){
           while(have_posts()){
               the_post();
           }
       } ?>
       ```
   
 * This will then take the selected Category or Tag and return only Posts that match
   that critera – if either or both are blank then they will be ignored.
 * This is used on an intranet, so I use the Permalinks (www.example.com/?cat=75)
   meaning I can capture data from the URL (Query String), but if you are using 
   friendly URLs (www.example.com/category/test) then you will need to find away
   of getting that information, which I’m not 100% sure how to do.
 * Hope that helps.
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378541)
 * I really appreciate you taking the time to help!
 * I now created an empty “Page” in wordpress called “Articles” and connected that
   to the template file “Media/Articles category” which is called “category.php”
   and for testing purposes only contains this:
    ´ <?php /** * [@package](https://wordpress.org/support/users/package/)
   WordPress * @subpackage Ztheme */ /* Template Name: Media/articles category */
 * ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    ´
 * Now, I loaded [http://zetterstrand.com/articles](http://zetterstrand.com/articles)
   expecting to see only a lot of zzzzzzzzzzz — but i once again get my home page,
   containing an “article post”!
 * I am totally confused now.
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378566)
 * Not sure I’m afraid – from the description that is exactly what I do on several
   pages and it works
 * Things to check –
    - Sounds silly – but have you clicked ‘Update Page’ after selecting the custom
      template? It’s an easy oversight to make.
    - Check the Reading settings to make sure that page is not set as your Posts
      page, as I believe that will superceed your custom template.
    - Look in to the template heirarchy. I’m not an expert by any means, so I may
      have missed something.
 * Hope that helps
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378577)
 * Thank you again for all the help, but my problems seem a bit worse that i beleived
   at first.
 * I am not using pages at all, so that’s not it. (i tried your example but it didnt
   work)
 * I just wanted to use a specific template when the blog showed categories.
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378617)
 * A Page (Posts, for example) can only use 1 template as far as I am aware. Perhaps
   do a search for Plugins that may allow a different template to be used in certain
   situations?
 * And just to clarify is it only one Category you are looking to display with the
   custom template, or just any Category when it is filtered?
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378689)
 * One category would be enough.
 * But, to clarify: I am not using “pages”.
    It’s the same loop, i just want to 
   change the look of the template for one of the categories.
 * Like described here:
    [http://codex.wordpress.org/Template_Hierarchy#The_General_Idea](http://codex.wordpress.org/Template_Hierarchy#The_General_Idea)
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378723)
 * Your other thread [http://wordpress.org/support/topic/362159](http://wordpress.org/support/topic/362159)
   wasn’t closed, but it is now, and I pointed it over to this thread. I also deleted
   another duplicate topic you started.
 *  Thread Starter [zet_kr](https://wordpress.org/support/users/zet_kr/)
 * (@zet_kr)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378758)
 * Sorry MichaelH, I did not mean to make a doublepost, I found no way to delete
   it.
 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378770)
 * Ok, after reading that I would say that, for example, if you are on ‘[http://www.example.com/news/&#8217](http://www.example.com/news/&#8217);
   then you would use index.php.
 * If you were on ‘[http://www.example.com/category/test&#8217](http://www.example.com/category/test&#8217);
   then WordPress would search for a template called category-{test_ID}.php. I wouldn’t
   have thought you needed to declare it as a template either, so scrap that suggestion.
 * Off the top of my head, the fact it is using index.php suggests that it can’t
   find category-15.php – are you certain you have copied it across. I’ve done that
   a few times where by I cannot work out why it won’t work and it’s because the
   file is still on my local computer rather than the web server!!
 * May also be worth looking at the category IDs, as sometimes you can be using 
   the ID of the Parent Category when you should be using the Child’s ID.
 * Sorry I can’t be more help.

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

The topic ‘Load custom category template?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 15 replies
 * 3 participants
 * Last reply from: [David Gard](https://wordpress.org/support/users/duck_boy/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/load-custom-category-template/#post-1378770)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
