WordPress.org

Ready to get started?Download WordPress

Forums

Specific template for subcategories doesnt work (16 posts)

  1. ponch
    Member
    Posted 5 years ago #

    I am using a specific template for one category, it's a mini link catalog on my site. I created a file category-22.php it works wonderful.

    I also created subcategories for this cat. But when I add new posts the page displays nothing. I tried some things:

    1) Created a category-30.php, category-31.php, category-32.php templates - nothing displays

    3) Installed plugins like "use pattern of the parent category" - nothing.

    Once I transform those subcategories into categories the templates work wonderful. It's ok to leave like that, but I want to preserve urls like http://mysite.com/catalog/design/
    So that the design remained a subcategory to catalog.

    What could be my mistake? Here is a code for category-22.php

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
    	<div id="content">
    
    <div style="width:85%;margin-top:20px;">
    <?php include (TEMPLATEPATH . '/3.php'); ?>	 
    
    <table><tr><td class="catalog"><?php wp_list_categories('include=30,31&title_li='); ?></td><td style="padding-left:30px;" class="catalog"><?php wp_list_categories('include=32,33&title_li='); ?></td></tr></table>
    
    <p>
    <p>
    <p>
    <?php
    query_posts($query_string.'&posts_per_page=10');?>
    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
       <div class="clearfloat">
    
    <div style="padding-top:10px;padding-left:10px;display:block;">
    		<div class="left"><p><?php $values = get_post_custom_values("Image"); echo $values[0]; ?></div><div style="margin-left:30px;"><?php the_content();?></div>
    				 </div> </div>
    
    		<?php endwhile; ?>
    
    		<div style="padding-top:20px;padding-left:5px;"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> </div>
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    	<?php endif; ?>
    
    <p>
    <p>
    
    </div>
    	</div>
    
    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    
    <?php get_footer(); ?>

    Please, help. I have no clue

  2. stvwlf
    Member
    Posted 5 years ago #

    Hi

    Your problem is here
    <?php wp_list_categories('include=30,31&title_li='); ?>

    You are using a template that only executes when category 22 is being displayed. Your query_posts excludes all posts except those in categories 30 and 31. since you are on a page displaying cat 22, posts from categories 30 and 31 are never going to be displayed on that page.

    On this post I describe how to set up a custom page that will display posts only from one category - you can use the custom category template as the basis of the custom page

    http://wordpress.org/support/topic/264482?replies=9#post-1053767

  3. ponch
    Member
    Posted 5 years ago #

    Thank you for answer, but I dont think you understood my problem. The posts on category 22 display fine.

    It's categories 30, 31, 32, 33 that appear blank. But only when I set them as subcategories to category 22. When I use that template on them, and they are independent categories everything is fine.

  4. ponch
    Member
    Posted 5 years ago #

    Also when I make category-30.php a subcategory to any normal cat in my blog, it keeps dispaying nothign. Even if I erase

    <table><tr><td class="catalog"><?php wp_list_categories('include=30,31&title_li='); ?></td><td style="padding-left:30px;" class="catalog"><?php wp_list_categories('include=32,33&title_li='); ?></td></tr></table>
    
    <p>
    <p>
    <p>
    <?php
    query_posts($query_string.'&posts_per_page=10');?>

    I dont know what's my mistake?

  5. ponch
    Member
    Posted 5 years ago #

    You are using a template that only executes when category 22 is being displayed.

    Why?

  6. ponch
    Member
    Posted 5 years ago #

    Tried like this in category-30.php

    <?php
    query_posts($query_string.'&posts_per_page=10&cat=30');?>

    Again, when Cat 30 is an independant category everything works fine, when a subcategory - blank

  7. stvwlf
    Member
    Posted 5 years ago #

    Tried like this in category-30.php

    <?php
    query_posts($query_string.'&posts_per_page=10&cat=30');?>

    Again, when Cat 30 is an independant category everything works fine, when a subcategory - blank

    a template named category-30.php by definition will be used when category 30 posts are being displayed. Thus there is no need for a query_posts statement in that template. What happens when you remove the query_posts entirely?

  8. ponch
    Member
    Posted 5 years ago #

    removed query_posts from category-30.php , also removed query_posts from its parent category 22 nothing changes. There is header, sidebar, everything, but no posts.

    Here is the code for category 22, I also tried "use_parent_category_template" plugin - still no posts.

    category-22.php (desired parent to cat 33)

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
    	<div id="content">
    
    <div style="width:85%;margin-top:20px;">
    <?php include (TEMPLATEPATH . '/3.php'); ?>	 
    
    <p>
    <p>
    <p> 
    
    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
       <div class="clearfloat">
    
    <div style="padding-top:10px;padding-left:10px;display:block;">
    		<div class="left"><p><?php $values = get_post_custom_values("Image"); echo $values[0]; ?></div> <div style="padding-left:30px;"><?php the_content();?></div>
    				 </div> </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>-->
    
    		<?php endwhile; ?>
    
    		<div style="padding-top:20px;padding-left:5px;"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> </div>
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    	<?php endif; ?>
    
    <p>
    <p>
    
    </div>
    	</div>
    
    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    
    <?php get_footer(); ?>
  9. stvwlf
    Member
    Posted 5 years ago #

    I am not completely following what you are attempting to do.

    Are you aware that when you use a template named category-22.php that it is only going to display posts from category 22, not from categories that are children of category 22, or parents of category 22?

    You might want to use an alternate approach of setting up if/else code in the main category.php template file. You can use similar code in other areas in category.php

    if ( is_category('22') || is_category('30') || is_category('31') || is_category('32') ) {
      include (TEMPLATEPATH . '/sidebar2.php');
    } else {
      get_sidebar();
    }
    
    $cat = 0;
    if (is_category('22')) {
       $cat = 22;
    } elseif (is_category('30')) {
      $cat = 30;
    } elseif .......
    }
    if ($cat > 0);
       query_posts("cat=$cat");
    endif;
  10. ponch
    Member
    Posted 5 years ago #

    Exactly, my problem is different, I am not trying to display some other category posts at category 22. I am just trying to apply a certain template to some categories (30, 31, 32, 33). But it works only when they are independent categories. When I ajust them as subcategories they display no posts. When I delete their templates, they work normally in both ways.

    I thought my explanation in the first post was quite simple and clear... Dont know

  11. stvwlf
    Member
    Posted 5 years ago #

    try the code approach i just suggested

  12. ponch
    Member
    Posted 5 years ago #

    Oh, thanx, but the code is too complicated, where exactly to put it, and where exactly to put in this code the desired pattern for these categories?

  13. stvwlf
    Member
    Posted 5 years ago #

    please post your category.php code in one pasetbin and the category-22.php code in another pastebin.

    post back here the URL's and what exactly is different between your default category template and what you are attempting to do in category22, category 30, etc.

    and is category-22.php any different than category-30.php other than including a differenty category?

    pastebin URL: http://wordpress.pastebin.ca/

  14. ponch
    Member
    Posted 5 years ago #

    No, absolutely identical.

  15. ponch
    Member
    Posted 5 years ago #

    That's why I tried "use-parent-temlate" plugins

  16. ponch
    Member
    Posted 5 years ago #

    I can show my site, but it's not in English, I am afraid you'll think I cant solve this problem, coz I am not a native english speaker, but I managed to build the site.

    Here is my usual category.php

    http://www.dietplan.ru/hudet/

    Here is my mini-link-catalog main page (category-22.php)

    http://www.dietplan.ru/catalog/

    Here is a category 30 - a subcategory to 22 and it is blank
    http://www.dietplan.ru/catalog/beauty/

    Here is a category 31 - an independent one and the pattern works fine

    http://www.dietplan.ru/pravpitanie/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.