if(is_home()&&!is_front_page())
3 个回答
- 投票数
-
- 2016-04-23
当设置静态页面以显示帖子时,这将显示页面的标题.
例如
我在首页上显示帖子... 它什么也不会做.
例如,如果我在标题为新闻的页面上显示帖子,... 它将在H1中显示新闻.
它用于在页面上显示帖子时显示页面标题,而在首页(主页)上显示博客帖子时不显示页面标题.
之所以这样做,是因为如果它在首页上,它将显示第一篇文章的标题,使其显示两次(一次在H1顶部,另一次在帖子循环浏览时).
This will display the title of the page when a static page is set to show posts.
E.g.
I show posts on my homepage... It'll do nothing.
If I, say, show posts on page titled News... It'll show News in H1.
This is used so that the title of the page is shown, whenever posts are shown on a page, but nothing when blog posts are shown on the front page (home page).
We do it because if it's on home page... it will show the title of the first post, making it appear twice (once at the top in H1 and again when posts are looped through).
-
谢谢Shramee.尝试找出它时,我在
中找到了我的博客索引页面的标题,但实际上并没有出现.我认为有些人只是用它来帮助使用屏幕阅读器的人,然后隐藏实际的文本,如果新手未评论/记录,这会使新手感到困惑.
Thank you Shramee. I found the title of my blog index page in awhen trying to figure it out but it doesn't actually appear anywhere. I think some themers use it only to help people using screen-readers, and then hide the actual text, which is a bit confusing for newbies if its not commented/documented.
- 0
- 2016-04-23
- olliew
-
嗯,这有助于了解在哪些上下文中使用了帖子(例如上例中的"新闻"),但是主要用于** SEO **,H1在帮助搜索机器人更好地了解页面内容方面发挥了重要作用.Well... It helps to know in which context posts are used, (like in above example for News) but it's mainly there for **SEO**, H1 plays a big role in helping search bots understand the page content better.
- 0
- 2016-04-24
- shramee
-
- 2016-09-19
这是正确的做法:
if ( is_front_page() && is_home() ) { // Default homepage } elseif ( is_front_page()){ // Static homepage } elseif ( is_home()){ // Blog page } else { // Everything else }
这是显示或更改主页和博客页面内容的唯一(正确)方法.
Here is how to do it right:
if ( is_front_page() && is_home() ) { // Default homepage } elseif ( is_front_page()){ // Static homepage } elseif ( is_home()){ // Blog page } else { // Everything else }
This is the only (right) way to display or alter content with your homepage and your blog page.
-
- 2016-04-23
我不确定"受欢迎",在我看来似乎不是这样(但是后来我没看那么多主题).
您似乎很好地掌握了每个条件的作用,因此这不会使您感到困惑.这结合了条件来检查博客索引是否显示在上,并且在首页上显示为不.
啊,我猜想
single_post_title()
的原因是它显示$wp_query->queried object
的标题(由主查询设置为当前上下文)),而不是全局的$post
(由迭代循环设置).在某些情况下,它们是相同的,但在情况检查不一样的情况下.循环将包含posts ,但是查询的对象将是page (除非我将所有内容混在一起:).
I am not sure about "popular", it doesn't seem so to me (but then I don't look at that many themes).
You seem to grasp fine what each conditional does, so this shouldn't be confusing to you. This combines conditions to check that blog index is being displayed and it's not at the front page.
Ah, the reason for
single_post_title()
I would guess is that it displays title for$wp_query->queried object
(set up by main query as current context), rather than$post
global (set up by iterating loop).In some circumstances these will be same, but not in such case as condition checks for. The loop will contain posts, but queried object will be page (unless I am mixing things up :).
-
我最近一直在浏览大量的模板,这很常见.您是对的,我了解循环的作用,只是我不明白为什么人们会选择以这种特定方式进行循环.为什么要使用single_post_title而不是the_title()?I've been looking through loads of templates recently and it is very common. You're right that I understand what the loop is doing, I just don't understand why people would choose to do it in this particular way. Why use single_post_title rather than the_title()?
- 0
- 2016-04-23
- olliew
我在index.php文件中经常看到以下代码.我了解在查看网站首页时(无论是显示博客文章索引还是静态页面),
is_front_page()
返回true,而在查看网站首页时,is_home()
返回true.博客文章索引(无论显示在首页还是静态页面上).我对使用以下代码仍然感到困惑-对于为什么这段代码如此受欢迎的任何解释,都将受到赞赏.