• 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:

    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="https://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)
  • 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

    (@zet_kr)

    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();
    ?>

    ?

    Yes, and then the template will appear in the drop down menu when you go to edit the Page.

    Thread Starter zet_kr

    (@zet_kr)

    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)
    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

    (@zet_kr)

    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 https://mypage.com/category/dogfood )

    BUT – now the index.php does not work by itself, so going to https://mypage.com results in a redirect error…..

    now what?

    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.

    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

    (@zet_kr)

    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 WordPress
    * @subpackage Ztheme
    */
    /*
    Template Name: Media/articles category
    */

    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

    Now, I loaded https://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.

    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

    (@zet_kr)

    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.

    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

    (@zet_kr)

    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:
    https://codex.www.ads-software.com/Template_Hierarchy#The_General_Idea

    Your other thread https://www.ads-software.com/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

    (@zet_kr)

    Sorry MichaelH, I did not mean to make a doublepost, I found no way to delete it.

    Ok, after reading that I would say that, for example, if you are on ‘https://www.example.com/news/&#8217; then you would use index.php.

    If you were on ‘https://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.