Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12916
    TheGoldFish
    Member

    Hi,

    I’m creating a website based on your theme but I have a problem.
    I need for my css rules to have the id of the current category put in the body when I’m in the article.

    For examples : I’m published an article in the category “Medias” so when i am in the “Medias” category, i’ve the id “category-medias” wich appears on the body. But when i clicked on the article, the body id “category-medias” desapear and is deplaced on the post div which is in “content”. But i need the id body “category-medias”.

    Sorry for my english and thanks for your help!

    #12949
    Sakin
    Keymaster

    @TheGoldFish: Sorry I don’t know which theme are you using, as you have use Free Themes section. Can you send me your site URL?

    #12972
    TheGoldFish
    Member

    Hi,
    Sorry my theme is the simple catch free.
    Thanks!

    #12974
    Sakin
    Keymaster

    @TheGoldFish: For that you need to use body_class filter hook and add it. See this http://codex.wordpress.org/Function_Reference/body_class

    #13053
    TheGoldFish
    Member

    Thanks for the link, it works!
    I’ve added this code into the funtions.php and my category appear in the “body”:

    // add category nicenames in body and post class
    function category_id_class($classes) {
    	global $post;
    	foreach((get_the_category($post->ID)) as $category)
    		$classes[] = $category->category_nicename;
    	return $classes;
    }
    add_filter('post_class', 'category_id_class');
    add_filter('body_class', 'category_id_class');

    Thanks for your help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Add an id on post which is in a category’ is closed to new replies.