I am creating a wordpress theme and I each category in theme has a designated colour. I want the wordpress code of simply printing out the name of the category into the id of the post so it can be set to the corresponding colour however every code I try gives html markup with it that messes up my code. Below is how I want this to work.
<article> <!-- POST -->
<h1>Post title</h1>
<h2 id="***Here is where I want to insert the code to print the post's category id***>Category Name (Same code as in the ID)</h2>
<img *featured image*>
<p>blah blah article summary</p>
</article>
Any help will be really appreciated!
I think you want this in your code...
<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>
Assuming you only have one category per post, should work just fine.
you can use
<?php single_cat_title(); //prints category in plain text ?>
Codex
or
<?php the_category(' '); //displays category with link ?>
Codex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With