SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help on creating If-statement in 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.

    HTML Code:
    <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>

  2. #2
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    Welcome to SitePoint!

    You can retrieve custom fields for a specific category like this:

    PHP Code:
    <?php if (in_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 ?>
    Maleika E. A. | Rockatee | Twitter | Dribbble



  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This worked! Thank you very much!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •