Make WordPress Core

Opened 14 months ago

Closed 3 months ago

#59767 closed enhancement (wontfix)

Front page template selection needs to be more granular

Reported by: flixos90's profile flixos90 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch
Focuses: template Cc:

Description

While #59759 has been focused on a concern with the TT4 home.html template, the reason why it came up as a problem in the first place is because TT4 chose to use the home.html template for the front page. That shouldn't be the case, but whichever path a block theme takes, there is no appropriate solution for the problem. Here's why:

  • If you have only a home.html template, it won't be used for the static front page.
  • If you have a front-page.html template and a home.html template, the front-page.html template will be used for the front page regardless of whether it is configured to display a static front page or the blog.

This was fine when we were using classic themes, as those themes would simply include a if ( is_home() ) { /* Show blog posts. */ } else { /* Show static page content. */ } in their PHP front-page.php template. But you can't do that in block theme templates, so we'll need a more appropriate solution. You cannot achieve this in block themes at the moment. That's why this is a bug ticket more than an enhancement.

I think there is a rather straightforward way to solve this problem for block themes, while also providing the same additional flexibility for classic theme templates:

  • For the front page, WordPress core should support an additional layer of templates, either front-page-home or front-page-static (depending on whether the home page is configured to show the blog or a static page).
  • Block themes could then provide front-page-home.html, front-page-static.html, and home.html, and thus would have the ability to cater for all 3 types of content.
  • Existing block themes wouldn't have any problem though, as in case front-page-home.html / front-page-static.html aren't present, WordPress core would still load front-page.html.
  • For classic themes, it wouldn't change much, just that they would now optionally be able to split their front-page.php template into two more distinct front-page-home.php and front-page-static.php templates.

Of course the home and static suffixes for the new front-page-* templates were just my initial ideas, there may be better names for those. My thinking behind those names is that home is aligned with the existing home.html (which is for better or worse synonymous with the blog in WordPress, e.g. is_home() returns true when on the blog page), while static simply describes the option of choosing a static page. Maybe blog would be more descriptive than home? Curious to hear others' thoughts.

Change History (11)

This ticket was mentioned in Slack in #core-themes by flixos90. View the logs.


14 months ago

This ticket was mentioned in PR #5592 on WordPress/wordpress-develop by @flixos90.


14 months ago
#2

  • Keywords has-patch added

This is an early draft PR for addressing the limitations outlined in the ticket below.

You can test it with any block theme or classic theme. For example with TT4:

  • Rename home.html to front-page-static.html.
  • Configure your WordPress site to show a static front page. You'll see that the front page will show the content in front-page-static.html.
  • Configure your WordPress site to show the latest posts on the front page. You'll see that the front page will show the content in index.html (which is the last fallback value for that template.
  • You could also duplicate index.html and rename it to front-page-home.html to achieve similar behavior.
  • Additionally, you could introduce a generic front-page.html template that would act as a fallback in case the front page is configured to neither display the latest posts nor a static front page. Realistically, this is not possible today per WordPress core limitations, but it goes to show this would support a future where the front page could be configured to show something different, or simply whatever the template includes.

Trac ticket: https://core.trac.wordpress.org/ticket/59767

#3 @swissspidy
11 months ago

  • Milestone changed from 6.5 to Future Release
  • Type changed from defect (bug) to enhancement

6.5 Beta is approaching soon and there hasn't been any traction on this in a while. More discussion is needed for this enhancement. Punting for now so it can be picked up in the next cycle.

#4 @flixos90
4 months ago

@poena @juanfra As the development leads for TT5, I would like to bring this to your attention for consideration for WordPress 6.7. For context, this was opened due to a limitation we ran into while creating the TT4 templates.

Basically, the way WordPress core handles the front-page template doesn't work well for block themes, as it ignores the configuration for whether the home page should display the "latest posts" or a "static front page". So a block theme has to populate this template with one or the other, and thus ignore the respective user choice, since we can't have a PHP conditional like if ( is_home() ) { /* Show blog posts. */ } else { /* Show static page content. */ } in a block theme template.

Therefore this ticket proposes support for (optional) granular templates for the two scenarios (e.g. front-page-static and front-page-blog). This is a simple change, but of course somewhat major as it introduces a new kind of supported template. I think it's worth moving this forward, as this could go hand in hand with a better handling of the user preference in the TT5 theme.

Please let me know your thoughts and any questions you may have.

#5 @flixos90
4 months ago

cc @luminuu @onemaggie since you were involved in the original problem we faced

#6 @flixos90
4 months ago

I just started a closely related Gutenberg discussion about the broader problem this ticket is a part of: https://github.com/WordPress/gutenberg/discussions/64620

@flixos90 commented on PR #5592:


3 months ago
#7

The PR now includes a proof of concept implementation to show how the more granular front page templates allow fixing the current problem.

## Current state

  • If Reading settings is set to "Latest posts", you see the business home page with latest posts in a list. ✅
  • If Reading settings is set to a static page, you see just that static page content, without any of the appealing UI built into the home page templates. 😐
  • If Reading settings is set to a static page and a custom Posts page is set, you see the business home page on that Posts page, although that is supposed to be a blog page with the posts being the primary content. ❌

## With this PR

  • If Reading settings is set to "Latest posts", you still see the business home page with latest posts in a list, no change here. ✅
  • If Reading settings is set to a static page, you now see the same business home page, but instead of the latest posts it has the contents of the static page embedded. ✅
  • If Reading settings is set to a static page and a custom Posts page is set, you see the posts in a 3-column grid as provided by the theme, i.e. now the posts are the main content. ✅

Of course this is just a proof of concept, and the UI and layout for those three scenarios could be modified. That said, I think the content displayed in the proof of concept is what would be expected in all three scenarios, and it's something that without the granular templates in Core would be impossible to achieve for a block theme today.

#8 @flixos90
3 months ago

I included a proof of concept for what this unlocks for block themes in https://github.com/WordPress/wordpress-develop/pull/5592, using the TT4 theme.

@luminuu @onemaggie @poena @juanfra I'd appreciate your feedback.

#9 follow-up: @poena
3 months ago

I personally don't believe that this is the way forward and I think the biggest problem with selecting your front page is not necessarily the problem that is being described here.

With block themes the user can place whatever they want in any template.
And I think that is what WordPress should embrace.

  • I don't think that a setting where you choose what your front page display is relevant anymore.
  • I don't think that displaying a *page* that you edit in the page editor is relevant anymore, when you are able to directly edit any template.
  • I don't think that choosing a template to only display a query loop is relevant anymore, because the query loop can be placed anywhere.

#10 in reply to: ↑ 9 @flixos90
3 months ago

Replying to poena:

I personally don't believe that this is the way forward and I think the biggest problem with selecting your front page is not necessarily the problem that is being described here.

With block themes the user can place whatever they want in any template.
And I think that is what WordPress should embrace.

  • I don't think that a setting where you choose what your front page display is relevant anymore.
  • I don't think that displaying a *page* that you edit in the page editor is relevant anymore, when you are able to directly edit any template.
  • I don't think that choosing a template to only display a query loop is relevant anymore, because the query loop can be placed anywhere.

I agree with almost everything that you're saying. That still doesn't make the limitation that this ticket describe less valid though.

The reality today is that there is a setting to choose those things, and it needs to be supported until a better solution is in place. So this is relevant until the UI has been revised completely to account for your (valid) overarching feedback.

This ticket is not about the future. It is about making what's supposed to work today actually work.

#11 @flixos90
3 months ago

  • Keywords 2nd-opinion removed
  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Per https://github.com/WordPress/gutenberg/discussions/64620#discussioncomment-10538827, the problem with this proposal is that it would also surface those templates to end users using the site editor. At this point, it would make things more confusing for end users. In other words, while for developers this template granularity would be okay, end user UX would suffer from it.

A better solution (also raised on that Gutenberg discussion) might be to deprecate/remove the home template entirely (at least for fresh sites) and instead rely on the blocks from the page_for_posts page itself to render the blog.

Note: See TracTickets for help on using tickets.