[英]How can I tell my wordpress to do something in the header if its a blog page?
In a previous post ( Don't show this if the url contains the following ) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header. 在上一篇文章中( 如果url包含以下内容,请勿显示此内容 )我询问如果用户在标头中使用/ blog加载URL时,如何使标头回显div。
What I didn't take into consideration, was that I don't want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs. 我没有考虑的是,我不希望div不仅显示在URL中的/ blog,还显示它的任何博客文章,而不仅仅是博客的索引页面。
How do I run a bit of code from my header.php if the page I'm looking at is a blog post? 如果我正在查看的页面是博客文章,如何从header.php运行一些代码?
You would use the Wordpress functions is_single() and is_page. 您将使用Wordpress函数is_single()和is_page。
if(!is_single() && !is_page() && !is_home() && !is_archive())
{
/* This will not display for any post, page, the home page, or an archive.
You can remove each is statement according to your needs */
}
For only posts, only use is_single, the same for page, home, and archive. 对于仅帖子,仅使用is_single,对页面,主页和存档使用相同。
The full listing of is_statements can be found here . is_statements的完整列表可以在这里找到。 Here are some others:
以下是一些其他内容:
is_home() : Home Page
is_front_page : Front Page
is_single() : Single Post
is_admin() : Admin Panel
is_sticky() : Sticky Post
is_page() : Page
is_category
is_tag
is_author
It's been long since I've played with wordpress but you can achieve a lot with using the conditional tags: 自从我玩过wordpress以来已经很久了,但是使用条件标签可以取得很多成就:
http://codex.wordpress.org/Conditional_Tags http://codex.wordpress.org/Conditional_Tags
Seems like is_single() might do what you want. 好像is_single()可能会做您想要的。 Eg:
例如:
if (!is_single())
{
// display div
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.