I have a problem with defining a wordpress variable for a class.
This is my code: I created a custom field for posts with the anme class.
Here I’d like to retrieve the class. If the custom field is empty, the class should be set to “col1” by default
$masonry_col_class = get_post_meta($post->ID, 'class', true);
if (!empty($masonry_col_class)){ $masonry_col_class='col1'; };
And here’s the output for the css:
<ul class="<?php echo $masonry_col_class ?>">
The if (!empty…) doesn’t seem to work though.
I would be thankful for any help.
-n-
You have actually written : if the variable I have just defined is NOT empty, then set it to “col1”. You should do exactly the opposite : if the variable IS empty, like this :
(as I guess your idea is : either the class is defined in the custom field and we have it here, or else I use the generic “col1” class… is that correct?