#7939 closed enhancement (fixed)
add body_class function
| Reported by: | kretzschmar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.8 |
| Component: | Template | Version: | 2.7.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Now that there is a dynamic class function for themes in the core (post_class), please add one for the body tag too (I would like to see something like the one of the sandbox theme).
Attachments (2)
Change History (21)
#2
@
18 years ago
- Component General → Template
- Type defect (bug) → enhancement
+1 Any theme lovers feel like knocking something up?
(I just tried to use it and was shocked to find, that WP didnt actually have one..)
#4
@
18 years ago
- Keywords has-patch added; needs-patch removed
Ended up basing it on the Sandbox one since it was more comprehensive, converted it to the WP coding style. I took out a few things like the date/time based classes which seemed excessive and would require more functions, and added an rtl class for RTL languages.
Here's the Sandbox code for comparison.
http://code.google.com/p/sandbox-theme/source/browse/trunk/functions.php?r=265#20
Might revisit it later and add some stuff back in; let me know if there's anything you think it needs.
#6
@
18 years ago
- Resolution fixed
- Status closed → reopened
- Version → 2.8
Ended up basing it on the Sandbox one
Hah, I nearly commented "I would've patched it with sandbox's one, But i absolutely hate it" :)
I dont have time to make up a patch, But could this get added to the start of the main If blocks? (Oh, It also needs a whitespace cleanup)
if ( is_singular() ) $classes[] = $wp_query->post->post_name;
ie:
if ( is_404() )
$classes[] = 'error404';
if ( is_singular() )
$classes[] = $wp_query->post->post_name;
if ( is_single() ) {
Having the current posts's slug in there is very handy for styling purposes.
The only other thing to say, Is whats the use of all the the_post()/rewind_post()'s? Most (if not all) of the info needed is already there in $wp_query->post, same with $wp_query->get why not just use get_query_var(), /endrant (Re-opening for the post slug, thats all)
#7
@
18 years ago
- Keywords needs-patch added; has-patch removed
I intended the patch as a first pass; I was planning on going through and replacing the calls to the_post()/rewind_post() when I had the chance (it is a strange idiom). I'll have a look at rolling your other suggestions into it when I have some time tomorrow.
#8
@
18 years ago
I intended the patch as a first pass
I thought as much :)
It does need some optimization I think, But the same would be said no matter where it came from.. At least we've got something in trunk now, and something to polish up! *strips the body_class related things out of his themes*
#10
@
18 years ago
The body_class() function currently adds the post id to the list of classes (eg postid-827).
Would it be possible to include another class for the page id (if a page is being displayed)?
eg: "pageid-828"
I could write a simple patch to do this, but I'm not sure if ionfish is still working on rewriting the function?
#11
follow-up:
↓ 12
@
18 years ago
- Keywords has-patch added; needs-patch removed
attachment 7939.2.diff added
Adds mine and jamescollins suggetions.
#12
in reply to: ↑ 11
@
18 years ago
Replying to DD32:
attachment 7939.2.diff added
Adds mine and jamescollins suggetions.
Looks good DD32.
#13
@
17 years ago
- Keywords tested added
The 7939.2.diff patch has been tested and looks good to me.
#14
@
17 years ago
- Version 2.8 → 2.7.1
Is there any chance of getting this committed in time for WP 2.8?
Thanks very much.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
New features are being bumped to 2.8 now.