$charlength) {
$subex = mb_substr($excerpt, 0, $charlength - 5);
$exwords = explode(' ', $subex);
$excut = -(mb_strlen($exwords[count($exwords) - 1]));
if ($excut < 0) {
echo mb_substr($subex, 0, $excut) . '...';
} else {
echo $subex . '...';
}
} else {
echo str_replace('[…]', '', $excerpt);
}
}
/*----*//*----*//*----*/
public static function get_excerpt_by_id($post_id, $excerpt_length = 50)
{
$the_post = get_post($post_id); /*Gets post ID */
$the_excerpt = $the_post->post_content; /*Gets post_content to be used as a basis for the excerpt */
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); /* Strips tags and images */
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if (count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$the_excerpt = implode(' ', $words);
endif;
return $the_excerpt;
}
/*----*//*----*//*----*/
public static function remove_last_comma($string = '')
{
if (substr($string, -1) == ',')
return substr($string, 0, -1);
else
return $string;
}
/*----*//*----*//*----*/
public static function post_nav()
{
global $post;
$previous = (is_attachment()) ? get_post($post->post_parent) : get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
if (!$next && !$previous)
return; ?>
'', 'image_catched' => true);
$output = preg_match_all('//i', $post->post_content, $matches);
if (isset($matches [1] [0])) {
$first_img['src'] = $matches [1] [0];
}
if (empty($first_img['src'])) {
$first_img['src'] = WDWT_IMG . 'default.png';
$first_img['image_catched'] = false;
}
return $first_img;
}
/*----*//*----*//*----*/
public static function first_image($width, $height, $url_or_img = 0)
{
$image_parametr = self::catch_that_image();
$thumb = $image_parametr['src'];
$class = '';
if (!$image_parametr['image_catched'])
$class = 'class="no_image"';
if ($thumb) {
$str = "
';
return $str;
}
}
/*----*//*----*//*----*/
public static function is_empty_thumb()
{
$thumb = get_post_custom_values("Image");
return empty($thumb);
}
/**
* returns image tag with image
* for containers of fixed size
* image fitted, cropped, centered
*/
public static function fixed_thumbnail($width, $height, $grab_image = true)
{
$tumb_id = get_post_thumbnail_id(get_the_ID());
$thumb_url = wp_get_attachment_image_src($tumb_id, array($width, $height));
$thumb_url = $thumb_url[0];
if ($grab_image) {
if (!$thumb_url) {
$thumb_url = self::catch_that_image();
$thumb_url = $thumb_url['src'];
}
}
if ($thumb_url) {
return '
';
} else {
return '';
}
}
/**
* returns image tag with image
* fits width of container
* height auto
*/
public static function auto_thumbnail($grab_image = true)
{
$scrset = '';
$tumb_id = get_post_thumbnail_id(get_the_ID());
$thumb_url = wp_get_attachment_image_src($tumb_id, 'full');
$thumb_url = $thumb_url[0];
if ($thumb_url) {
if (function_exists('wp_get_attachment_image_srcset')) {
$scrset = 'srcset="' . esc_attr(wp_get_attachment_image_srcset($tumb_id, 'full')) . '"';
}
} else if ($grab_image) {
$thumb_url = self::catch_that_image();
$thumb_url = $thumb_url['src'];
}
if ($thumb_url) {
return '
';
} else {
return '';
}
}
/*-----@return url of first image in the post content, or empty string if has no image-----*/
public static function post_image_url()
{
$thumb_url = self::catch_that_image();
if (isset($thumb_url['image_catched'])) {
if (!$thumb_url['image_catched']) {
$thumb_url = '';
} else {
$thumb_url = $thumb_url['src'];
}
}
return $thumb_url;
}
/*WooCommerce support */
public static function wdwt_wrapper_start()
{
global $wdwt_front;
$single_title_bg = $wdwt_front->get_param('single_title_bg', array(), true);
?>