0

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?

2

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...

  • 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 ?>"> – jkupczak 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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