php - how to display wordpress post excerpt only on the image post which has excerpt on hover -
i have created gridview of wordpress posts, , trying display excerpt on mouse hover each thumbnail(post)
if thumbnail(post)
don't have excerpt content should not display that.
<?php $args = array('post_type' => 'press'); $counter = 1; //start counter $grids = 4; //grids per row global $query_string; //need make pagination work /*setting our custom query (in here setting show 12 posts per page , eliminate 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 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 display .excerpt on hover else display 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 right hand side column elseif($counter == $grids) : ?> <div class="clear"></div> <?php $counter = 0; endif; ?> <?php $counter++; endwhile; //pagination can go here if want it. endif; ?>
if understand correctly, want don't want display post if there no thumbnail associated it. if right, should add condition in if statement ( if($counter >= 1) ). add condition (get_post_thumbnail() !== ") current if statement , should desire. example below:
if(($counter >= 1 && (get_post_thumbnail() !== ""))
edit: after reading what have added. suggest use get_the_excerpt() function. returns value if there excerpt present, otherwise returns empty string. check out code example below:
$my_excerpt = get_the_excerpt(); if ( $my_excerpt != '' ) { // print excerpt }
using code , javascript or css, should able achieve desired effect.
Comments
Post a Comment