#7939 closed enhancement (fixed)
add body_class function
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.7.1 |
Component: | Template | Keywords: | |
Focuses: | Cc: |
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
@
16 years ago
- Component changed from General to Template
- Type changed from defect (bug) to 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
@
16 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
@
16 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
- Version set to 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
@
16 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
@
16 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
@
16 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
@
16 years ago
- Keywords has-patch added; needs-patch removed
attachment 7939.2.diff added
Adds mine and jamescollins suggetions.
#12
in reply to:
↑ 11
@
16 years ago
Replying to DD32:
attachment 7939.2.diff added
Adds mine and jamescollins suggetions.
Looks good DD32.
#13
@
16 years ago
- Keywords tested added
The 7939.2.diff
patch has been tested and looks good to me.
#14
@
16 years ago
- Version changed from 2.8 to 2.7.1
Is there any chance of getting this committed in time for WP 2.8?
Thanks very much.
New features are being bumped to 2.8 now.