我需要显示多个样式的帖子;新闻1和新闻2。我所遇到的问题是,我需要以不同的风格显示每个帖子。对于News1中的文章,IE需要有日期和分享按钮,但对于News2,我不需要这个。
我有一个自定义字段设置到部分News2 off称为"存档类别",并可以使用get_post_meta。
我的问题只是条件语句,应该在posts文件。
如果有人能帮忙的话,我将不胜感激。
谢谢
在single.php中,获取自定义字段值,然后根据该值,调用不同的模板部分:
get_template_part( 'prefix', 'other-parts-of-the-file-except-extension' );
在模板部分文件中,以不同的方式布局单个帖子/页面。
为了详细说明,实际的布局代码应该写在模板部件文件中。single.php只检查自定义字段的值,并根据该值调用不同的模板部分文件。
伪代码将是(在single.php或single-post.php或single-customposttype.php中,无论您使用哪个):
<php
$value=get the custom field value; // replace this with your function to get the value
if($value=='News 1')
get_template_part('template', 'news1'); // then you'll put layout in template-news1.php
else
get_template_part('template', 'news2'); // layout in template-news2.php
?>