ThemeShaper Forums » Thematic

filter the category loop for one specific category

(8 posts)
  • Started 9 years ago by chicho
  • Latest reply from chicho
  • This topic is not resolved
  1. hi all, I'm a noob in programing, then be comprensive with me.

    Well, I'm triying to make a photo page where are thumbnails of photos that come from custom-fields in post categorized as photoblog.

    To do that I made a category page, called category-8.php, and make a page in WP and I linked both with "page links to" plugin.

    I tried to do it looking at gallery theme but in functions.php when apply the fiter function remove_category_loop(), it removes for all categories.

    How can remove the category_loop for "photoblog" category?

    Thanks in advance

    Chicho

    Posted 9 years ago #
  2. So im hearing that you've created a new category template for a specific category. That may not be necessary unless you want to drastically change the category template for that category.

    I'll work on this

    -Gene

    Posted 9 years ago #
  3. Here's one way to do it... add this to your functions.php in your child theme

    function remove_category_loop(){ // its an action not a filter so first remove the thematic action
        remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    add_action('init','remove_category_loop');
    
    function child_category_loop() { // now rebuild your version of the action
    
     while (have_posts()) : the_post();
    
     if (is_category('8')) { // category id 8 -- custom fields addition to the thematic category loop
    
    	 // general example of custom field usage from within a function
    	 global $post; // needed to get $post->ID below
    
         $postimageurl = get_post_meta($post->ID , 'post-img', true);
    
         if ($postimageurl) {?>
            <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" /></a>
            <?php } else { ?>
            <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="/wp-content/themes/your-child-theme-name-here/images/default.gif" alt="Default Pic"/></a>
            <?php }
        } // everything beyond this point gets applied to all category archives ?>
    
            <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
               <?php thematic_postheader(); ?>
               <div class="entry-content">
                 <?php thematic_content(); ?>
               </div>
               <?php thematic_postfooter(); ?>
            </div><!-- .post -->
    
         <?php endwhile;
    }
    add_action('thematic_categoryloop', 'child_category_loop');
    Posted 9 years ago #
  4. Thanks em hr, I have created a new template category because I removed the sidebar and triyng to use all space to make like gallery with that thumbnails.

    The issue is that in that template shows now the thumbnails and the post. Following each other, Iǘe been trying to remove tha category loop in the template but it doesn't works.

    Posted 9 years ago #
  5. Post the code from your category-8.php template and I'll take a look

    Posted 9 years ago #
  6. It's a simple category.php but with a reference of a container2 and content2 that give me a full area in the page.

    <?php
    global $options;
    foreach ($options as $value) {
    if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; }
    else { $$value['id'] = get_option( $value['id'] ); }
    }
    ?>
    <?php get_header() ?>

    <div id="container2">
    <div id="content2">

    <?php thematic_page_title() ?>

    <?php thematic_navigation_above();?>

    <?php thematic_above_categoryloop() ?>

    <?php thematic_categoryloop() ?>

    <?php thematic_below_categoryloop() ?>

    <?php thematic_navigation_below();?>

    </div><!-- #content -->
    </div><!-- #container -->

    <?php thematic_sidebar() ?>
    <?php get_footer() ?>

    Posted 9 years ago #
  7. It looks like you not really doing anything here that you couldn't do with css and a couple of functions. You'll have to use the slug of the category get the right body class just look at the class attribute for the <body> in the source. If the slug for that category is 'photostream' then the body class specific to this page would be 'category-photostream' so in your stylesheet you would add the following with your preferred styles added to get the desired changes to your layout on that page.

    .category-photostream #container {  width: 960px;  }
    .category-photostream #content { width: 940px;   }

    Now assuming the category id is '8' add this to your functions.php to remove the sidebar on that page and rebuild the loop so that only a custom field generated image links you to the single post page:

    function phototstream_remove_sidebar() {
        global $post;
    	if ( is_category('8')) {
     		return FALSE;     //  switch off the sidebar
    	} else {
    		return TRUE; 	     // otherwise leave on
    	}
    }
    add_filter('thematic_sidebar', 'phototstream_remove_sidebar');
    
    // its an action not a filter so first remove the thematic action
    function remove_category_loop(){
        remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    add_action('init','remove_category_loop');
    
    function child_category_loop() { // now rebuild your version of the action
    
     while (have_posts()) : the_post();
    
     if (is_category('8')) { // category id 8 -- custom fields addition to the thematic category loop
    
    	 // general example of custom field usage from within a function
    	 global $post; // needed to get $post->ID below
    
         $postimageurl = get_post_meta($post->ID , 'post-img', true); ?>
    
    	 <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    
     	 <?php if ($postimageurl) {
    
     	 			// here is where your image url gets pulled from the custom field key 'post-img' ?>
             		<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" /></a>
    
              			<?php } else { 
    
              		// here is where your defualt image url gets pulled if the custom field key 'post-img' is not set ?>
             		<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="/wp-content/themes/your-child-theme-name-here/images/default.gif" alt="Default Pic"/></a>
              			<?php }
        		} else { 
    
        	// this is the treatment all of the other category archive pages get ?>
    
            <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
               <?php thematic_postheader(); ?>
               <div class="entry-content">
                 <?php thematic_content(); ?>
               </div>
               <?php thematic_postfooter(); ?>
            </div><!-- .post -->
    
    	<?php } ?>
    
      <?php endwhile;
    }
    add_action('thematic_categoryloop', 'child_category_loop');

    Good Luck - Gene

    Posted 9 years ago #
  8. I just comment that

    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">

    and it works perfect for me.

    Thanks Gene

    Posted 9 years ago #

RSS feed for this topic

Reply

You must log in to post.