Wordpress How to Check whether it is POST or PAGE

2019-02-16 06:49发布

How to check if an article is a post or a page in WordPress?

标签: wordpress
7条回答
别忘想泡老子
2楼-- · 2019-02-16 07:06

It's for developer, if you are not a developer you can also check current page type. You have to just inspect particular page and see body tag. If theme is build with basic WordPress rules then body tag have classes related to page or single page. These classes may b included the post type, template name, file name, page id and many more.

查看更多
来,给爷笑一个
3楼-- · 2019-02-16 07:09

You can use the is_page() and is_single() functions.

查看更多
Viruses.
4楼-- · 2019-02-16 07:09

If you're looping through a collection of posts/pages (say, on a search results page), then is_single() and is_page() won't be of any use. In this situation, you could grab the global $post object (of type WP_Post) and examine the $post->post_type property. Possible values include 'post' and 'page'.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-02-16 07:20

is_singular() returns true for a single post, page or attachment

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-02-16 07:20

You mean that is_single() will return true if it is a post ? (not a page), am I right,

I like that, I think you wrong, because I have a plugin show some text on only post, I'm using is_single() but It also show on pages.

Please advice.

Thanks

查看更多
戒情不戒烟
7楼-- · 2019-02-16 07:24

if you want y¡to know the page that list the posts , and you are using the posts page option in the configuration, You should use is_home().

查看更多
登录 后发表回答