• Resolved xionkid

    (@xionkid)


    Hi,

    Okey, I need some help that is pretty simple. On my blog i make some posts that are NSFW. I want those posts to have a different title colour in the main post feed on the blogs homepage. I can do the css myself however, I need help with the php code to assign a specific class to a post title that has a specific category. How do I do this?

    here is the code right now

    if ( is_single() ) :
    				the_title( '<h1 class="entry-title" )>', '</h1>' );
    			else :
    				the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
    			endif;

    how do i add the class to title based on the category?

    Please help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey there.

    You didn’t post a link so I couldn’t look on your site, but if you take a look at the default Twenty Fourteen theme you’ll see that a class gets added with category- prepended first. Like this if the category was called Uncategorized:

    .category-uncategorized

    The header should be within that class. You mentioned that you’re good with CSS so I assume you can take it from here, but if you need anything else then please let me know.

    Have a great weekend.

    Thread Starter xionkid

    (@xionkid)

    Yeah, it’s tweny fourteen theme. and the adress is [NSFW] http://xn--frspel-wxa.se/ please tell me how to do it. I must add something to the code i mentioned, right? I tried just adding a class like .category-uncategorized to my child theme css, but it does nothing because the title has no class besides class=”entry-title”

    Hey there,

    Nope, nothing to add to your code. It’s all CSS. So you have a category there called video, to target that title we could do this:

    .category-video .entry-title a {color:#ff0c3e;}

    That changes the title to red for example.

    You then have another category called Relationer and the slug has a number 2 in it:

    .category-relationer-2 .entry-title a {color:#ff0c3e;}

    That’s how you target them with CSS to change their colours. Just change the hex as required and target the specific class for the category.

    Take care.

    Thread Starter xionkid

    (@xionkid)

    THANK YOU! I serioulsy want to kiss you right now. I understand what you wrote in the first post now. Thank you again!

    You’re most certainly welcome! 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[NSFW] Assign specific class to post title, based on the category it's in?’ is closed to new replies.