I have created a gridview of wordpress posts, and i am trying to display excerpt on mouse hover for each thumbnail(post)
but if any thumbnail(post)
don't have any excerpt content it should not display that.
<?php
$args = array('post_type' => 'press');
$counter = 1; //start counter
$grids = 4; //Grids per row
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts ( $args );//query_posts($query_string . '&caller_get_posts=6&posts_per_page=12');
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
//Show the left hand side column
if($counter >= 1) :
?>
<div class="griditemleft" style="position:relative;">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
<div class="excerpt"><?php if post have excerpt then display .excerpt on hover else display only the thumbnail?>
</div>
<h2 class="press-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>
<h2 class="press-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php
//Show the right hand side column
elseif($counter == $grids) :
?>
<div class="clear"></div>
<?php
$counter = 0;
endif;
?>
<?php
$counter++;
endwhile;
//Pagination can go here if you want it.
endif;
?>
If I understand you correctly, you want don't want to display a post if there is no thumbnail associated with it. If I am right, then what you should do is add another condition in the if statement ( if($counter >= 1) ). add this condition (get_post_thumbnail() !== ") to the current if statement and it should do as you desire. Example is below:
if(($counter >= 1 && (get_post_thumbnail() !== ""))
Edit: After reading what what you have added. I would suggest that you use the get_the_excerpt() function . It returns a value if there is an excerpt present, otherwise it returns an empty string. Check out the code example below:
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// print excerpt
}
Using this code and some JavaScript or CSS, you should be able to achieve your desired effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.