Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to insert the category or page ID of the current page into my HTML so that I can use CSS to style each page based on what it is.

For example, if had a category called "News" and it's ID was 5, my source code would end up having in it. Then I could use CSS to style #category-id-5 to suit my needs.

How would I accomplish this?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

get_queried_object() has a property with that ID.

But you don't really need it, because the <body> tag should have a class with the current category / page ID...

share|improve this answer
    
For whatever reason the theme I'm using didn't have this functionality already added to the body tag. And unfortunately get_queried_object() didn't work for me. <?php $my-page = $wp_query -> get_queried_object() ?> <body class="my-page-<?php echo $my-page ?>"> –  jimmykup Oct 1 '11 at 5:40
    
it should be my_page->ID, and my_page->term_id for categories –  onetrickpony Oct 1 '11 at 7:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.