WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. torkil
    Member
    Posted 8 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
    Member
    Posted 8 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.
    See:
    http://codex.wordpress.org/Pages (and the Templates section)
    also:
    http://codex.wordpress.org/Template_Hierarchy

    However, if you want to go with one file (index) check out this:
    http://codex.wordpress.org/Conditional_Tags

  3. torkil
    Member
    Posted 8 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:

    is_page()

    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