Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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 '11 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 '11 at 13:50
1  
if(get_post_type() == 'page'): –  EarnestoDev Oct 21 '11 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 '11 at 10:23

2 Answers 2

up vote 1 down vote accepted
<?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; ?>
share|improve this answer
1  
Exactly what I was looking for, thank you! –  japanworm Oct 22 '11 at 12:57
if (is_page('your_static_page_slug'))
share|improve this answer
    
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 '11 at 10:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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