简体   繁体   English

如果它是博客页面,如何告诉我的wordpress在标题中执行某些操作?

[英]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.

相关问题 在我的Wordpress主题中,如何为博客页面添加分页? - In my Wordpress theme, how can I add pagination for the blog page? 在我的 php 中的 header 之后我该怎么做? - How can i do something after my header in php? 如何在wordpress网站上获取博客页面,以在帖子编辑器中显示文本和图像,使它们看起来相同? - How do I get the blog page on my wordpress site to show the text and images in the post editor to look the same? 我如何知道WordPress中博客页面的父页面ID? - How can I know the parent page ID of the blog page in WordPress? 如何将博客页面包含在自定义WordPress主题中? - How do I include the blog page in a custom WordPress theme? 如何在我的WordPress博客上配置漂亮的网址? - How do I configure pretty urls on my WordPress blog? 如何安全地将我的wordpress博客移植到localhost? - How can I safely port my wordpress blog to localhost? 如何在不使用AngularJS加载新页面的情况下让我的wordpress网站在同一页面上显示博客文章? - How can I get my wordpress site to show a blog post in the same page without loading a new page using AngularJS? 我如何在我的html网站中添加wordpress帖子,博客位于myurl.com/blog - how can i add wordpress posts into my html site the blog is located at myurl.com/blog WordPress博客与主页(html)分开; 如何包括Wordpress功能? - Wordpress blog separate from main (html) page; how do I include Wordpress functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM