WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use this function, but I don't know correctly what is the perfect way..

The code:

<li  id="post-<?php the_ID(); ?>" <?php post_class(get_the_content() == "" ? "no-content" : ""); ?> <?php post_class(has_post_thumbnail() ? "" : "no-image"); ?>>

There are two if statements. Currently only the first working, the second not but if I remove the first <?php post_class(get_the_content() == "" ? "no-content" : ""); ?> the second working. How can in combine these lines?

share|improve this question
up vote 1 down vote accepted

Use the post_class filter to test multiple conditions:

function wpa_post_class( $classes ) {
    global $post;
    if( ! has_post_thumbnail() ) $classes[] = "no-image";
    if( get_the_content() == "" ) $classes[] = "no-content";
    return $classes;
add_filter( 'post_class', 'wpa_post_class' );

Then your html will just be:

<li  id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
share|improve this answer
Thank you, just one question. Is it possible to use this function in the template file like my code above? – hepii110 Mar 30 '13 at 18:16
If your theme has a functions.php file, that's where the top snippet ought to go. The latter you can use in your template file. +1 – Johannes Pille Mar 30 '13 at 18:22

Your Answer


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.