Created
October 22, 2014 07:58
-
-
Save nguyenvanduocit/4cb7751b6c6ca9b241ac to your computer and use it in GitHub Desktop.
CE.add title, alt to image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function post_thumbnail_html ($html, $post_id, $post_thumbnail_id, $size, $attr) { | |
global $ce_config, $post; | |
// if($size !== '') return $html; | |
if( $post && $post->post_type !== 'ad' ) return $html; | |
$list_view = isset($_COOKIE['ce_list_view']) ? $_COOKIE['ce_list_view'] : $ce_config['default_grid']; | |
if(is_single()) { | |
$list_view = 'grid'; | |
} | |
if(is_author()) { | |
$list_view = 'list'; | |
} | |
if($list_view == 'grid') { | |
$size = 'ad-thumbnail-grid'; | |
$src = TEMPLATEURL.'/img/no_image.gif'; | |
}else { | |
$size = 'ad-thumbnail-list'; | |
$src = TEMPLATEURL.'/img/no_image-list.gif'; | |
} | |
global $isMobile; | |
if( $isMobile && $html != '' ) { | |
return $html; | |
} | |
if( $html == '' ) { | |
$html = '<img data-grid="'.TEMPLATEURL.'/img/no_image.gif" data-list="'.TEMPLATEURL.'/img/no_image-list.gif" src="'.$src.'" class="attachment-ad-thumbnail wp-post-image" alt="">'; | |
}else{ | |
$alt = trim(strip_tags( get_post_meta($post_thumbnail_id, '_wp_attachment_image_alt', true) )); | |
$title = get_the_title( $post_thumbnail_id ); | |
$src_list = wp_get_attachment_image_src( $post_thumbnail_id, 'ad-thumbnail-list' ); | |
$src_grid = wp_get_attachment_image_src( $post_thumbnail_id, 'ad-thumbnail-grid' ); | |
if( $size == 'ad-thumbnail-list') { | |
$src = $src_list; | |
}else { | |
$src = $src_grid; | |
} | |
if( !et_is_mobile() ) | |
$html = '<img data-list="'.$src_list[0].'" data-grid="'.$src_grid[0].'" src="'.$src[0].'" data-src="'.$src[0].'" class="attachment-ad-thumbnail wp-post-image" alt="' . $alt . '" title="' . $title . '">'; | |
else | |
$html = '<img data-list="'.$src_list[0].'" data-grid="'.$src_grid[0].'" src="'.$src[0].'" class="attachment-ad-thumbnail wp-post-image" alt="' . $alt . '" title="' . $title . '">'; | |
} | |
return $html; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* slider template in single ad | |
*/ | |
global $post; | |
$attachment = get_children( array( | |
'numberposts' => 15, | |
'order' => 'ASC', | |
'post_mime_type' => 'image', | |
'post_parent' => $post->ID, | |
'post_type' => 'attachment' | |
),OBJECT ); | |
$slides = array(); | |
$thumb_id = get_post_thumbnail_id($post->ID); | |
if( $thumb_id ) { | |
$alt = trim(strip_tags( get_post_meta($thumb_id, '_wp_attachment_image_alt', true) )); | |
$title = get_the_title( $thumb_id ); | |
$src = wp_get_attachment_image_src( $thumb_id , 'ad-slide'); | |
$src_full = wp_get_attachment_image_src( $thumb_id , 'ad-slide-large'); | |
$src_origin = wp_get_attachment_image_src( $thumb_id, 'full' ); | |
$slides[] = $src; | |
} | |
$i = 0; | |
/** | |
* ad images | |
*/ | |
if( !empty($attachment) || !empty($slides) ) { ?> | |
<div class="col-md-12 bg-slide-listing" style="opacity: 0;"> | |
<span class="btn-zoom in"><i class="fa fa-expand"></i></span> | |
<div class="slide-listing-wraper"> | |
<ul class="slide-listing"> | |
<?php if( isset($attachment[$thumb_id]) ) unset($attachment[$thumb_id]); ?> | |
<li id="0" style="text-align : center;"> | |
<a href="<?php echo $src_origin[0]; ?>" class="item-slider" rel="item-slider" title="<?php echo get_the_title($thumb_id); ?>" target="_blank" > | |
<img src="<?php echo $src[0] ?>" data-normal = "<?php echo $src[0]; ?>" data-full="<?php echo $src_full[0] ?>" alt="<?php echo $alt ?>" title="<?php echo $title; ?>"/> | |
</a> | |
</li> | |
<?php $i++; ?> | |
<?php | |
foreach ( $attachment as $key => $att) { | |
$alt = trim(strip_tags( get_post_meta($att->ID, '_wp_attachment_image_alt', true) )); | |
$title = "Image : " . $alt;//get_the_title( $att->ID ); //disable for perfomance; | |
$image = wp_get_attachment_image_src( $att->ID, 'ad-slide' ); | |
$image_full = wp_get_attachment_image_src( $att->ID, 'ad-slide-large' ); | |
$image_origin = wp_get_attachment_image_src( $att->ID, 'full' ); | |
$slides[] = $image | |
?> | |
<li id="<?php echo $i; ?>" style="text-align : center;"> | |
<a href="<?php echo $image_origin[0]; ?>" class="item-slider" rel ="item-slider" title="<?php echo get_the_title($att->ID); ?>" target="_blank" > | |
<img src="<?php echo $image[0] ?>" data-normal = "<?php echo $image[0]; ?>" data-full="<?php echo $image_full[0] ?>" alt="<?php echo $alt ?>" title="<?php echo $title; ?>"/> | |
</a> | |
</li> | |
<?php $i++; } ?> | |
</ul> | |
</div> | |
<?php if(count($slides) > 1 ) { ?> | |
<div class="bg-slide-thumbnails"> | |
<span class="prev-slide"><span class="icon-prev"></span></span> | |
<div class="slide-thumbnails"> | |
<div id="bx-pager" class="contronl-slide"> | |
<?php foreach ($slides as $key => $slide) { ?> | |
<a class="<?php if($key == 0) echo 'active'; ?>" data-slide-index="<?php echo $key ?>" href=""><img src="<?php echo $slide[0] ?>" /></a> | |
<?php } ?> | |
</div> | |
</div> | |
<span class="next-slide"><span class="icon-next"></span></span> | |
</div> | |
<?php } ?> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment