Posted By

nerdfiles on 01/23/10


Tagged

wordpress


Versions (?)

Display WP Page/Post name


 / Published in: PHP
 

I use this to display the page/post name in @class of the . It's pretty self-explanatory; dealing with numbers in @class for CSS is undesirable. This way, you can specify a background for "child pages" by name, etc. Plus, neither bodyclass() nor hybridbody_class() sets a "hierarchical" relationship between child and parent pages in @class of .

  1. function body_class_page_name($echo = false) {
  2. global $post;
  3. $parent_title = strtolower(str_replace(" ", "-", get_the_title($post->post_parent)));
  4. $page_name = strtolower(str_replace(" ", "-", get_the_title()));
  5.  
  6. if ($parent_title == $page_name) $parent_title=" home-parent";
  7. else $parent_title = " ".$parent_title."-parent";
  8.  
  9. $page_name = " ".$page_name;
  10.  
  11. if ($echo == true) echo $parent_title.$page_name;
  12. else return $parent_title.$page_name;
  13. }

Report this snippet  

You need to login to post a comment.