Should post_class() and body_class() be used in the “page.php” template?
-
I am building a custom WordPress theme for one of my clients and I noticed the new post_class() and body_class() functions in WordPress 2.8 and thought I would take advantage of them. I like the idea behind them and they should lead to some cool ways of creating custom themes, but if I use the body_class() on the <body> tag and post_class() on the “post” <div> on a Page (page.php) I run into problems.
The Default WordPress theme doesn’t use the post_class() in the “page.php” template and I am guessing this is because they ran into the same problem I did.
If you have the post_class() and body_class() function on a Page then your <body> tag will be assigned the “page” CSS class and your post <div> will also be assigned the “page” CSS class. I know there are workarounds by using multiple CSS selectors in my “style.css” file to narrow it down to the exact “page” CSS class I want to style, but it would be easier and more straight forward if both of these functions didn’t assign the same CSS class name when used on a Page.
On single posts (single.php) and other pages (index.php) under the default theme I see that they are using both of these functions together without any problems.
1.) Should I never use both of these in my “page.php” template file?
2.) Is this a bug and will it be addressed in a future update?
3.) Am I using the post_class() and body_class() functions in a way they were never expected to be used?I am just trying to find some direction on if I should consider using both of these function on Pages or if I should use the Default theme method for “page.php” and leaving the post_class() function out completely as shown below:
<div class="post" id="post-<?php the_ID(); ?>">
- The topic ‘Should post_class() and body_class() be used in the “page.php” template?’ is closed to new replies.