[resolved] How can I test if I am at a page or a post (php if-test)? (3 posts)

  1. torkil
    Posted 10 years ago #

    I have this plugin that allows user to give my posts a rating, but it is showing on the pages on my site too. How can I write an if-test that only shows this rating on posts and not on pages?

    What is the variable (if any) that I need to check out?

  2. moshu
    Posted 10 years ago #

    I can't see the ratings anywhere - but maybe you disabled the plugin.
    Now, the easiest way is to create a page.php template file (that doesn't have the code for rating), WP will use it automatically for displaying your Pages.
    http://codex.wordpress.org/Pages (and the Templates section)

    However, if you want to go with one file (index) check out this:

  3. torkil
    Posted 10 years ago #

    I fixed it, thanks for the link to the codex. I've been reading up on it this passed week.

    the test I run is this:


    It will return true if the page is indeed a page...

    Check out the results on http://www.torkiljohnsen.com/hattrick

    You will see that the About page is without a rating now :)

Topic Closed

This topic has been closed to new replies.

About this Topic