In the following code I would like to remove the div that wrap all the code and pass its class to article, but I do not know how to pass the variable $termString inside the post_class.
Can anybody help me?
<div class="<?php echo $termsString;?>"> <article id="post-<?php the_ID(); ?>" <?php post_class('card'); ?>> <?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'img-fluid card-img-top')); ?> <div class="overlay"></div> <div class="card-body text-right"> <h6 class="card-title"><?php the_title(); ?></h6> <p>Text description for this item</p> </div> <a class="card-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"></a> </article> </div>
So, I have this now, and it is what I expected:
<article id="post-<?php the_ID(); ?>" <?php post_class('card grid-item wow fadeInUp ' . $termsString); ?>>
but I also need to add to these classes another class that comes from a custom field which name is "columns" and with value "col-12".
This is what I am trying, but I think there's some syntax error, the result I see from the Firefox inspector is "Array" instead of the value of "columns":
<?php $custom_values = get_post_meta($post->ID, 'columns', true); ?> <?php $classes = array( 'card', 'grid-item', 'wow', 'fadeInUp', $termsString, $custom_values ); ?> <article id="post-<?php the_ID(); ?>" <?php post_class( $classes ); ?>>
Edit: get_post_meta requires a third parameter, "false" returns the Array (default), "true" returns only the first result (NOT as an array). Now it is working! Thanks a lot.