Categories or Slugs: Changing the BODY ID CSS for single.php
-
I’m adding back blogging functionality to our design shop’s website. It’s an older custom WordPress template using WP as a CMS and the first I did mostly in house. So it’s a real hybrid mess of techniques. I am designer. But my php skills are weak.
To have blog functionality I have to have the single.php template active, which I had previously deactivated since we were not doing any traditional blogging.
Now I need to add the single.php template back. BUT in the header.php I used the slug to define my body ID for the CSS selectors on any given page. Each page hasa unique BODY ID for both navigation and some custom post styles. I know. I know. All this probably should have gone in the functions.php. But it was easier at the time.
Now the problem is getting my hacky php to recognize an additional way of finding the correct Body ID via the new blog category rahter than slug on the single.php template. What I’ve been trying doesn’t seem to be working. See the “blahg” section in the code below:
<body id="<?php $slug = $post->post_name; $post_data = get_post($post->post_parent); $pslug = $post_data->post_name; $category = get_the_category(); $categoryName = $category[0]->cat_name; echo $categoryName; if ($slug=="what" || $pslug=="what") echo "what"; elseif ($slug=="who" || $pslug=="who") echo "who"; elseif ($slug=="where" || $pslug=="where") echo "where"; // STORE SECTION elseif ($slug=="store" || $pslug=="store") echo "store"; // BLAHG SECTION elseif ($slug=="blahg" || $pslug=="blahg") echo "blahg"; elseif($categoryName=="blahg") echo "blahg"; else echo "home"; ?>">
This PHP just returns the BODY ID “blahg” and doesn’t default the ‘else echo “home”:’
I’m sure this something simple. It’s driving me crazy. Does this make sense?Anybody have any ideas?
- The topic ‘Categories or Slugs: Changing the BODY ID CSS for single.php’ is closed to new replies.