WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 2 weeks ago

#6848 closed defect (bug) (wontfix)

is_front_page() should only return true on the front page

Reported by: Pinoy.ca Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Template Keywords: has-patch
Focuses: Cc:

Description

As per documentation these functions return true only at the site's first page. It can be shown that these functions return true for the second, third and subsequent pages as well (?p=2, 3, and so on)

is_home() on the documentation is ambigious with "is this the blog view homepage" (i.e., uses the index.php template) and has been around since 2.1. In addition to its dependency with get_home_template(), there may already been plugins who anticipate this long-standing bug.

is_front_page() has no dependencies, so I suggest that is_front_page() be corrected, moving forward. There can be only one front page.

Attachments (1)

6848.diff (678 bytes) - added by Denis-de-Bernardy 6 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 @DD327 years ago

  • Keywords reporter-feedback added

It appears to work as expected for me.

/wordpress/ is_front_page() = true
/wordpress/?p=2 /wordpress/?p=16 /wordpress/?p=143 /wordpress/2008/04/test/ /wordpress/page-name/ = false

What do you have Settings -> Reading -> "Front page displays" Set to?

I've tried both Static page & latest posts with the same results.

comment:2 @Pinoy.ca7 years ago

  • Component changed from General to Template
  • Summary changed from is_front_page() and is_home() erroneously returns true on /blog/?p=2 and so forth to is_front_page() and is_home() erroneously returns true on /blog/page/2 and so forth

Oh no I'm mistaken, DD32. I was referring to /wordpress/page/2, /wordpress/page/3 and so forth. (Sorry... It's too late in the night around here.)

comment:3 @DD327 years ago

  • Keywords 2nd-opinion added; reporter-feedback removed

I was referring to /wordpress/page/2, /wordpress/page/3 and so forth.

Ahh, In that case, Yes, I can confirm it does return true on those pages.

However, I'm not sure if your interpratation is correct, As it *is* the "Front Page", As in, Its not a Single View or a Page View, Or an archive view, Its the "Front Page" View, showing the overflow posts..

From Docs:

Returns true when the main blog page is being displayed and the 'Settings->Reading->Front page displays' is set to "Your latest posts",

Which is the case in question, As its the Main blog view, Granted, in this case, the 2nd page of the main blog view.

I guess its open to interpratation, I'm not sure how it was intended to work, I'm just outlining why *I* think its correct as it is given what i know of it..

comment:4 @Pinoy.ca7 years ago

is_front_page() was markjaquith's solution in February last year. In that discussion, unfortunately, the participants didn't talk about /blog/page/2 and so forth.

I would believe that everyone who said "front of the site" there was referring to blog_info("home"). Thus, there can be only one front page.

By the way, the fix for this is replacing

if ( 'posts' == get_option('show_on_front') && is_home() )

on query.php with

if ( 'posts' == get_option('show_on_front') && is_home() && !is_paged() )

comment:5 @Denis-de-Bernardy7 years ago

I think it should stay as it is now.

is_home() should return true on paged pages since it really means is_blog().

the case for is_front_page() is probably worth discussing, but you can always add a !is_paged() call if you only want to be showing your stuff on the site's "true" front page.

D.

comment:6 follow-up: @Viper007Bond7 years ago

I think it's best how it is now. If it was switched to the suggested change, it'd be really hard to find front page, but page 2.

However, as Denis-de-Bernardy said, it's easy to exclude 2nd pages and stuff via is_paged().

comment:7 in reply to: ↑ 6 ; follow-up: @Pinoy.ca7 years ago

Replying to Viper007Bond:

it'd be really hard to find front page, but page 2.

I'm sorry I don't understand you.

comment:8 in reply to: ↑ 7 @Viper007Bond7 years ago

Replying to Pinoy.ca:

Replying to Viper007Bond:

it'd be really hard to find front page, but page 2.

I'm sorry I don't understand you.

If is_front_page() returned false on /page/2/, that would make it harder to do stuff (like display a message or whatever) on those pages while avoiding doing it on like page 2 of the latest posts (you could do hackery to display like only a certain category on your homepage for example).

However, if it continues to return true, it's easy to exclude paged results via !is_paged().

Basically, it's a lot more flexible how it is now. It's easier to exclude pages (now) than it is is determine if it's the front of the site, but paged (proposed).

Get it? Sorry, it's hard to explain, heh.

comment:9 @Pinoy.ca7 years ago

Get it? Sorry, it's hard to explain, heh.

No I still do not understand. It is no better to exclude pages (now) and be unclear (now) than it is to determine if it is front of the site, but paged (proposed) (this is done with is_home() && is_paged()). The effort is the same, but which is clearer?

There's no need to create our own definition of a widely-used term and make ourselves a "special case," like this

Front page, n.

  1. The first page of a newspaper.
  1. The starting page, or root page, of a website.
  1. Wordpress. The root page of a blog and also its /page/2 and so forth. If you want to refer only to the root page, you have to combine is_front_page() with !is_paged(), for example, if (is_front_page() && !is_paged()) echo "Welcome to my blog";.

Would you imagine you're writing a book about WordPress and try explaining this ....

comment:10 @ryan7 years ago

  • Milestone changed from 2.5.2 to 2.9

Milestone 2.5.2 deleted

@Denis-de-Bernardy6 years ago

comment:11 @Denis-de-Bernardy6 years ago

  • Keywords has-patch dev-feedback added; is_front_page is_home 2nd-opinion removed
  • Milestone changed from 2.9 to 2.7.1
  • Summary changed from is_front_page() and is_home() erroneously returns true on /blog/page/2 and so forth to is_front_page() should only return true on the front page
  • Version changed from 2.5 to 2.7

comment:12 @DD326 years ago

I'm tempted to close this as invalid/wontfix.

its a template tag for telling the page type. A page is still a post if you're on its 2nd page split, An archive is still an archive if you're on the 5th page, Its still the blog listings if you're on the previous postings.. Its still the "front page", even if its showing the previous paged content, because its a template tag, Not about the content of the page, just the page type.

comment:13 @DD326 years ago

  • Version changed from 2.7 to 2.5

combined with the fact its been acting like this for 3 major versions now.. I really suggest closing as invalid, I'm not going to close though, and leave it for someone else.

Also, Leave the version set to the older version... A unfixed bug in 2.5 is going to remain in 2.7.. if it doesnt.. then the tickets closed..

comment:14 @Denis-de-Bernardy6 years ago

Yeah, but it's a special template tag. As I understand things, is_front_page() was introduced to distinguish the static front page from the blog's front page.

If I want to know if I'm browsing the blog page (whether it is on the front page or on pages that list previous posts), I'd use is_home() rather than is_front_page().

One potential argument against the diff could if someone who inserts a paged static page on his front page; he might end up wishing that is_front_page() returned true. But everyone else would expect is_front_page() to return true on just that -- the site's front page.

For me, either way works, provided I know what to expect... :-)

comment:15 @DD326 years ago

Thats exactly the thing.. It IS the front page, A Static frontpage is the front page, So are its paged components.. They're part of the front page.

is_archive() IS a special template tag, just as much as is_front_page(), is_front_page() was introduced to tell a static page apart from a posts-home-page, And thats all, Not for the very first page of the static page..

If you're using a paged static page as your front page, AND you want to modify only the first page of it, You know you want to exclude it via is_paged() - exactly what you're doing..

Thats just my opinion.. And i dont see the point in changing it since its been this way since the start..

comment:16 @Denis-de-Bernardy6 years ago

  • Keywords dev-feedback removed
  • Resolution set to wontfix
  • Status changed from new to closed

will close as wontfix then...

comment:17 @DrewAPicture2 weeks ago

  • Milestone 2.7.2 deleted
Note: See TracTickets for help on using tickets.