Support » Plugins and Hacks » How can I test if I am at a page or a post (php if-test)?
10 years, 9 months 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?
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:
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 🙂