目前,无论是帖子还是静态页面,搜索结果都以相同的方式显示。由于我不想在静态页面上显示评论数量和类别,我想知道如何做到这一点。
代码:(Update October 22nd)
<?php
if(get_post_type() == \'page\') : ?>
<div class="recent_postMetaSingle">
<img src="<?php bloginfo(\'template_directory\'); ?>/images/eye.png" alt="Views" title="views" /> <?php print_page_views(get_the_ID(\'\')); ?>
<p>This is a static page!</p></div>
<?php endif; ?>
<div class="recent_postMetaSingle">
<img src="<?php bloginfo(\'template_directory\'); ?>/images/eye.png" alt="Views" title="views" /> <?php print_page_views(get_the_ID(\'\')); ?> <img src="<?php bloginfo(\'template_directory\'); ?>/images/comments2.png" alt="Comments" title="comments" /> <?php comments_popup_link(\'0\', \'10\', \'%\'); ?>
</div>
<div class="recent_category"><?php the_category(\' // \') ?></div>
谢谢你迄今为止的帮助。我更新了代码。现在,它只显示在静态页面上,但条件标记下面的HTML标记也会显示出来,我希望它只显示在帖子中。我想我必须在什么地方贴上“else”标签?我只是不知道如何正确地实施它。
提前多谢!
最合适的回答,由SO网友:EarnestoDev 整理而成
<?php if(get_post_type() == \'page\'): // Only pages ?>
<div class="recent_postMetaSingle">
<img src="<?php bloginfo(\'template_directory\'); ?>/images/eye.png" alt="Views" title="views" />
<?php print_page_views(get_the_ID(\'\')); ?>
<p>This is a static page!</p></div>
<?php elseif(get_post_type() == \'post\'): // If not page, Only posts ?>
<div class="recent_postMetaSingle">
<img src="<?php bloginfo(\'template_directory\'); ?>/images/eye.png" alt="Views" title="views" />
<?php print_page_views(get_the_ID(\'\')); ?>
<img src="<?php bloginfo(\'template_directory\'); ?>/images/comments2.png" alt="Comments" title="comments" />
<?php comments_popup_link(\'0\', \'10\', \'%\'); ?>
</div>
<div class="recent_category"><?php the_category(\' // \') ?></div>
<?php endif; ?>