Opened 9 years ago
Last modified 8 days ago
#35164 reviewing enhancement
Singular body class and main post post class
Reported by: | danielpataki | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | needs-patch |
Focuses: | Cc: |
Description
I think it would be pretty useful to be able to style all singular posts with one selector. I thought it might be a good idea to output ".singular" using the body_class()
function. This would allow people to target all singular pages.
In addition, detecting the main post on the page would be useful if someone had some related posts on a singular page. So the class ".main-post" could by added using the post_class()
function.
I'm using this method via hooks in a theme so I can say: .singular .main-post {}
which allows me to style posts and pages with one selector and give a default look to all custom post types.
Attachments (1)
Change History (17)
#1
follow-up:
↓ 2
@
9 years ago
- Component changed from General to Themes
- Version trunk deleted
I'm +1 for singular
, it's added by twentyeleven and twentyfouteen so the need is demonstrated.
My reading of is_main_query
is it will always be true in the body, and if it isn't it's likely an indication the pre_get_posts
filter should be used. If it isn't true, it will have been altered in code at which point a body_class
filter can be used.
-1 on main-post
#2
in reply to:
↑ 1
@
9 years ago
Replying to peterwilsoncc:
My reading of
is_main_query
is it will always be true in the body, and if it isn't it's likely an indication thepre_get_posts
filter should be used. If it isn't true, it will have been altered in code at which point abody_class
filter can be used.
You're completely right, good point! The feature would still be useful if we could detect the post output by the main query. For example: I would like my single post and single page titles to be centered. However, if I retrieve related posts below, I wouldn't want them to be centered. Hence:
.singular .main-post .entry-title{ text-align:center; }
That said, I agree that this may not be a big issue. If there is a related posts section underneath that would likely have a wrapper class which you would use to style things anyway.
#3
@
9 years ago
- Keywords has-patch added
Thinking the same as @peterwilsoncc, +1 on singular
, -1 on main-post
as I don't think it can be done in a reliable way.
#5
@
9 years ago
- Owner set to johnbillion
- Resolution set to fixed
- Status changed from new to closed
In 36112:
#6
@
9 years ago
Awesome, thanks everyone for your input! I still think main-post would be a great addition, although I see why it can't be done reliably. Do you think it would be worth creating a separate ticket for it, perhaps for further down the line?
Also, would .main-post be helpful? In my mind it would solve some problems, but I wouldn't call myself a master of HTML and CSS architecture so perhaps I'm over-thinking this :)
#7
@
9 years ago
This change broke the TwentyEleven theme, which made its own assumptions about a body_class
called singular
(see 36510). The fix for this is probably adjusting TwentyEleven. But I wanted to leave a pointer here over to the ticket noting this issue.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
9 years ago
#10
@
9 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from 4.5 to Awaiting Review
Reverted in [37249].
Adds the singular body class and the main-post post class