1

Currently the search results are all shown in the same way, no matter if it's a post or a static page. As I don't want the comment count and the categories to show up for static pages, I was wondering how to do it.

The code: (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('')); ?> &nbsp;&nbsp;&nbsp;          <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>

Thanks for your help so far. I updated the code. Now, it only shows up on static pages, but the HTML markup below the conditional tag also shows up and I want that to only show up for posts. I guess I have to put an "else" tag somewhere? I just don't know how to implement it correctly.

Thanks a lot in advance!

4
  • I think you're on the right tracking using get_post_type(). Of course, if you use != 'page' it shows up on posts and not on pages. Could you clarify the problem?
    – Geert
    Oct 21, 2011 at 13:39
  • Thank you for your comment. Hm, well what you see in the second code snippet is what I want to show ONLY if it's a static page, but not a post, so how would I have to modify the code above in order to achieve that? :)
    – japanworm
    Oct 21, 2011 at 13:50
  • 1
    if(get_post_type() == 'page'): Oct 21, 2011 at 16:53
  • @EarnestoDev: Hello. That worked fine. Now, I still need to figure out how to implement it correctly. Please see my updated quesiton. Thanks a lot :)
    – japanworm
    Oct 22, 2011 at 10:23

2 Answers 2

3
<?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('')); ?>
        &nbsp;&nbsp;&nbsp;
        <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; ?>
0
1
if (is_page('your_static_page_slug'))
1
  • Hello and thank you. I tried it the following way: <?php if (is_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; ?> However this outputs a syntax error (unexpected T_STRING). I tried it in a different way and this works better, but I still have a small issue. Please see my updated question, thank you :)
    – japanworm
    Oct 22, 2011 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.