WordPress中is_single()与is_singular()的区别详解
简单的认为is_sigular()相当于is_single()||is_page()||is_attachment()没有什么大问题。
也就是说,有is_single()||is_page()
1 | < ?php if ( is_single()||is_page() ) { ?> |
的地方,都可以替换成is_singular()
1 | < ?php if ( is_singular() ) { ?> |
但是其实上述这种理解不是太准确。来比较一下is_single()与is_sigular()的文档。
is_single()是可以加参数的。参数可以是post_id,post_slug,post_title。2.5之后还可以同时对这几个参数加以判断。
当不带参数时,返回的是当前显示的是不是一个单独的post(而且类型不是page和attachment)。
而带了参数,返回的就是当前显示的是不是编号/标题/标志为“XXX”的那篇post。
在数据库里,is_single不仅要查询ID是否存在,还要保证type是“post”而不是“page”,“attachment”甚至“revision”。
is_sigular()则简单的多。就是当前显示的是不是一条单独的post所形成的页面。
在数据库里,is_sigular()也只是判断ID是否存在即可。
免插件实现WordPress评论回复邮件通知的三种方法 Js字符串操作函数详解
Hello there, I found your blog by means of Google while looking for a related subject, your
website got here up, it appears to be like great. I’ve bookmarked
it in my google bookmarks.
Hello there, just was aware of your weblog via Google, and located that it is really
informative. I am going to watch out for brussels. I will
appreciate should you proceed this in future. Many people will likely
be benefited from your writing. Cheers!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?