How to Customize your Post in WordPress

11 Nov

Screen shot 2011-11-11 at 4.50.29 PM

Why would you want to do this? Maybe you want post of a certain category to be different, or highlight by author in the post or comments? This week I used a function called called post_class to make data sheets with a different logo to match each company. Each company is a different category so I wanted to target the category of the post to make my changes with css.

This function automatically add classes, depending on the page view, for

.post-id
.post
.attachment
.sticky
.hentry (hAtom microformat pages)
.category-ID
.category-name
.tag-name
.format-name

Open up your page that contains your loop and find the div that holds your post, most themes will name this div post. Add the function so it looks like this.

<div id=”post-<?php the_ID(); ?>” <?php post_class(‘class-name’); ?>>

If your category was If you check your source code it should return values like this

<div id=”post-4564″>

Now add the style to your CSS. So if your category was parties, your style would be .category-parties { }

If you are using the twenty eleven theme that comes with WordPress you can see the Post_class function in your functions.php. SO you ONLY have to add the CSS class. It doesn’t get any easier!

Additional reading:
WordPress Codex
WP Beginner

 
  

No comments yet

Leave a Reply