0

In my archive page I want a certain category not to display. The rest of the code I'm adding, but it goes to a custom page

The logic is like, if is category=33, then include photo.php

<div class="latest_from_category">


<h2 class="latest_frm_cat_title archive_title"><?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */
 if (is_category()) { 
        ?>
   <?php 
     _e('', 'bilanti'); ?> 
   '<?php echo single_cat_title(); ?>' 
    <?php _e('Archive For', 'bilanti'); ?>                                  

   <?php /* If this is a tag archive */  
    } elseif( is_tag() ) { ?>
   <?php _e('Archive for the', 'bilanti'); ?> 
   <?php single_tag_title(); ?> Tag

  <?php /* If this is a daily archive */ 
    } elseif (is_day()) { ?>
  <?php _e('Archive for', 'bilanti'); ?> 
  <?php the_time('F jS, Y'); ?>                                     

  <?php /* If this is a monthly archive */ 
  } elseif (is_month()) { ?>
  <?php _e('Archive for', 'bilanti'); ?>
  <?php the_time('F, Y'); ?>                                    

  <?php /* If this is a yearly archive */ 
   } elseif (is_year()) { ?>
 <?php _e('Archive for', 'bilanti'); ?> 
 <?php the_time('Y'); ?>

  <?php /* If this is a search */ 
    } elseif (is_search()) { ?>
    <?php _e('Search Results', 'bilanti'); ?>

    <?php /* If this is an author archive */ 
        } elseif (is_author()) { ?>
        <?php _e('Author Archive', 'bilanti'); ?>

        <?php /* If this is a paged archive */
    } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>

    <?php _e('Blog Archives', 'bilanti'); ?>                                        
    <?php } ?></h2> 
   <?php get_template_part( 'post-excerpt' ); // Post Excerpt (post-excerpt.php) ?>

   <?php else : ?>
  <h3 class="archive_not_found">404 <span>not found</span></h3>
  <?php endif; ?>                           
    </div>

What should the exact code be?

1
  • 1
    Please indent your code properly before you add it to your question. As it stand, I can't read it (and most other people, specially mobile users) as most of your code is outside the code block. – Pieter Goosen Jul 16 '14 at 11:26
2

You could use template_include conditionally.

add_filter( 'template_include', 'wpsites_photo_page_template', 99 );

function wpsites_photo_page_template( $template ) {

    if ( is_category('33') ) {
        $new_template = locate_template( array( 'photo.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }

    return $template;
}
1
  • i was thinking n searching for something like this thanx – Code Smith Jul 19 '14 at 6:11
0

Well, the template hierarchy allows you to use a custom template file for categories.

http://codex.wordpress.org/Template_Hierarchy#Category_display

If you want a special template for the category 33, you just save the template file as category-33.php in the theme folder.

Happy Coding,

Kuchenundkakao

1
  • yup i already found it thanx anyway – Code Smith Jul 19 '14 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.