2011-10-22 102 views
1

我正在使用Wordpress。我有一个电影评论网站叫做http://filmblurb.org。对于我的博客帖子,我试图创建不同类别的帖子。在“评论”类别下,我有一个“详细信息”框,作为我所有评论的元信息。问题是,当我尝试创建一个具有“功能”或其他类别的帖子时,“详细信息”框仍然存在。基本上,我想尝试创建一个PHP if语句,当我只写一个“评论”帖子时,它只会返回下面的代码序列。我在Wordpress中使用“get_post_meta”标签来填写这个“详细信息”框,用于填写每篇“评论”文章。示例文章可以在这里找到:http://www.filmblurb.org/reviews/97。有人可以帮助我吗?我会很感激。如果我需要更多地解释,请告诉我。Wordpress上的PHP条件语句帮助

<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> 

回答

3
<?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; ?> 

该参数可以是类别名称,slug或ID。 进一步参考检查the wordpress codex on the conditional tag "is_category()"

0

您有几个选择。

最好的一个可能是为每个后期类别创建一个特殊的模板。 如果你不知道什么样的模板,请在这里了解一切: http://codex.wordpress.org/Pages#Page_Templates

其他的方法是在CSS中。

在body标签中,您可以输入短代码,该短代码将返回有关您当前类别页面的一些信息。

通过使用特定的类,您可以将.box类设置为显示:无。

我希望这已经够清楚了。

+0

我很抱歉地指出,这大多不值得一读。 **页面**模板的名称出于某种原因。它们适用于页面,而不是帖子。理论上,.box div可以被css隐藏,但即使如此,也必须根据类别给予额外的类或ID。这又会需要is_category条件标签。用代码示例证明我错了,但是我没有看到[shortcode](http://codex.wordpress.org/Shortcode_API)是如何实现这一点的。其实这个答案只值得赞扬,但我一天的表现太好了。 –