PHP conditional statement help on WordPress

I’m using WordPress. I have a movie review website called http://filmblurb.org. For my blog posts, I’m trying to create posts with different categories. Under the “Reviews” category, I have a “Details” box that serves as meta information for all my reviews. The problem is when I try to create a post that has the category of “Features” or something else, that “Details” box still remains. Basically, I want to try to create a PHP if statement that will only return the following code sequence when I only write a “Reviews” post. I’m using the “get_post_meta” tag in WordPress to fill in this “Details” box for every “Reviews” post I write. A sample post can be found here: http://www.filmblurb.org/reviews/97. Can anybody help me on this? I would appreciate it. Let me know if I need to explain more.

<div class="box">
    <div class="boxheader">Details</div>
    <div class="text">
    <h1>Genre</h1>
    <p><?php echo get_post_meta($post->ID, 'genre', true); ?></p>
    <h1>Rated</h1>
    <p><?php echo get_post_meta($post->ID, 'rated', true); ?></p>
    <h1>Release Date</h1>
    <p><?php echo get_post_meta($post->ID, 'releasedate', true); ?></p>
    <h1>Runtime</h1>
    <p><?php echo get_post_meta($post->ID, 'runtime', true); ?></p>
    <h1>Director</h1>
    <p><?php echo get_post_meta($post->ID, 'director', true); ?></p>
    <h1>Cast</h1>
    <p><?php echo get_post_meta($post->ID, 'cast', true); ?></p>
    <h1>Grade</h1>
    <p><?php echo get_post_meta($post->ID, 'grade', true); ?></p>
    </div>
</div>

Related posts

Leave a Reply

2 comments

  1.  <?php if(is_category('reviews')) : ?>
         <div class="box">
             <div class="boxheader">Details</div>
             <div class="text">
                 <h1>Genre</h1>
                 <p><?php echo get_post_meta($post->ID, 'genre', true); ?></p>
                 <h1>Rated</h1>
                 <p><?php echo get_post_meta($post->ID, 'rated', true); ?></p>
                 <h1>Release Date</h1>
                 <p><?php echo get_post_meta($post->ID, 'releasedate', true); ?></p>
                 <h1>Runtime</h1>
                 <p><?php echo get_post_meta($post->ID, 'runtime', true); ?></p>
                 <h1>Director</h1>
                 <p><?php echo get_post_meta($post->ID, 'director', true); ?></p>
                 <h1>Cast</h1>
                 <p><?php echo get_post_meta($post->ID, 'cast', true); ?></p>
                 <h1>Grade</h1>
                 <p><?php echo get_post_meta($post->ID, 'grade', true); ?></p>
             </div>
         </div>
     <?php endif; ?>
    

    The parameter can be the category name, slug or ID.
    For further reference check the wordpress codex on the conditional tag “is_category()”

  2. You have several options for this.

    The best one is probably creating a special template for every post-category.
    If you don’t know what templates are, learn all about it here:
    http://codex.wordpress.org/Pages#Page_Templates

    Other ways to do this are in the CSS.

    in the body tag you can enter shortcode that will return some information regarding your current category page.

    By using specific class, you can set .box class to display:none.

    I hope this is clear enough.