Jump to content

Archived

This topic is now archived and is closed to further replies.

renderinnovations

CSS Per Category

Recommended Posts

renderinnovations

Hey guys, spent hours tryign to figure this out.  I wanted to do a custom body class, but pagelines is already calling their function:

 

<body <?php body_class( pagelines_body_classes() ); ?>>

 

I wanted to add $mycatclass where pagelines_body_classes is.  The reason I want to do that is, I'm tying to output a category name for each post so that I can customize posts based on their category.

 

I want to disable sidebars for any posts that fall under a specific category, but I can't do it without adding a body class to output the category name.

 

Now I found where the pagelines_body_classes lay; lib.body.php  but I'm not sure how to add my class along with it.

 

Thoughts?

Share this post


Link to post
Share on other sites
Danny

Hi,

 

Use a child theme and add the following snippet of code to the functions.php file. I found this snippet doing a quick search and added it myself and it appears to be working as intended.

 

add_filter('body_class','add_category_to_single');
function add_category_to_single($classes, $class) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug to the $classes array
$classes[] = $category->category_nicename;
}
}
// return the $classes array
return $classes;
}
 
If you're not currently using a child theme, then you're free to use the basic one I created here - http://dannyholt.github.io/skeleton
 
You can see in the body tag that the omfgwtfbbquber class has been added, this is the category that post belongs to. - https://cloudup.com/cNknWaqc38c

Please search our forums, before posting!

Share this post


Link to post
Share on other sites
renderinnovations

Hey, so I installed the child theme, added the above code to the function.  Keep in mind i'm using 1.1.8.  I assume you're using the higher version?

 

This is the error I get   https://www.evernote.com/shard/s106/sh/a1b7bf47-5711-40db-914a-89550aee9406/ce6caa7cb2395011a0837b396156f5c8

 

http://premiere1limousine.com/Premieredup/

 

Thanks

AB

Share this post


Link to post
Share on other sites
Danny

Can you take a screenshot of the code you have added to your child themes functions.php file. Please do a screenshot and not just paste the code here, as I need to see the whole file.

 

Mine looks like this and I receive no such error - https://cloudup.com/cpZbnew4aMa


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

AH, don't use the WordPress editor dude, it sucks really bad. I recommend you use an FTP client such as Transmit and configure it so that you can open files via a code editor, then copy and paste the code into the functions.php file. I use Atom.io and Transmit.

 

https://atom.io/

http://panic.com/transmit/

 

See my screenshot above to see how my code is formatted.

 

Also copy and paste this code below instead of the one I pasted above, as it format may cause an issue.

 

https://gist.github.com/anonymous/da1b0eeef5e789e6ca30


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Danny

Not sure, I have never used cPanels code editor before. Therefore, download my functions.php file that I know works, as it's working for me.

 

http://ge.tt/7598Kxj1/v/0?c

 

Then replace it via FTP with the one you currently have.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
renderinnovations

Uploaded directly, still a no go. So odd.  Is it the version?  

Share this post


Link to post
Share on other sites
renderinnovations

Maybe it's a cache too, can you take a look at the link to see if it's showing wonky for you?

 

Thanks again for your help, this has been very odd

Share this post


Link to post
Share on other sites
renderinnovations

It's the 2nd $class that gave it the error,  I'm apparently missing that somewhere in the rest of the wp folder.

 

AB

Share this post


Link to post
Share on other sites
renderinnovations

This has been solved.  The extra $class wasn't needed. 

 

Thanks for your help.

AB

Share this post


Link to post
Share on other sites
Danny

Do you have WP_DEBUG set to true, as I have not needed to remove any code for it to work ?


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
renderinnovations

I don't have it enabled, I could, but either way, it seems to work just fine now.  Super odd haha

Share this post


Link to post
Share on other sites
Danny

haha, OK np, but yeah rather odd! :D


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • Lisa Haran
      By Lisa Haran+
      Hi 
      I have a map here http://www.iloveoffset.com/maps/
      I want to add several pointer locations to the map, but when I do they do not appear.
      On this map there are 2 pointer locations and as you can there is only one visible.
      Earlier today I added 7 and could only see 4 so there is something odd going on.
      My theme is up to date
    • clj182
      By clj182+
      Hello,
      I've been having trouble unlocking the template section for past couple of weeks. When I try clicking nothing happens. 
      I've deleted my custom css and removed plugins. Im down to having only the following plugins:
      Akismet
      Contact Form 7
      DMS Professional Tools
      Pagelines Updater
      WooCommerce
      It was working fine before i have no idea what's going on with it.
    • flourishdesignstudio
      By flourishdesignstudio+
      My DMS 2 site http://www.heart-stone.com/ will not save any new custom css... I can still edit templates and publish those but any custom css that I enter never saves.
      All WP files, themes, and plugins are up to date. 
      Any thought about what might be causing this?
    • flourishdesignstudio
      By flourishdesignstudio+
      Is there a way to edit the custom CSS via FTP? I know I can edit the custom code in the Chrome editor but is there a file path I can use to find and edit the CSS directly from our FTP?
      Thanks in advance for the help!
    • nizami
      By nizami+
      Using navbar section with correctly configured WP menu to display main navigation at https://elenaangel.com. 
      All fine in desktop viewport. Menu displays twice in hamburger mode. How to fix this please? 

×