Function Reference: geodir_max_excerpt

Summary

Limit the listing excerpt.

Description

This function limits excerpt characters and display “read more” link.

Global Values

$post
(object) (required) The current post object.

Default: None

Package

GeoDirectory

Parameters

$charlength
(string|int) (required) The character length.

Default: None

Return Values

(string)
  • The modified excerpt.

Change Log

Since: 1.0.0

Source File

geodir_max_excerpt() is located in geodirectory-functions/custom_functions.php [Line: 94]

Source Code

function geodir_max_excerpt( $charlength ) {
	global $post;
	if ( $charlength == '0' ) {
		return;
	}
	$out = '';

	$temp_post = $post;
	$excerpt   = get_the_excerpt();

	$charlength ++;
	$excerpt_more = function_exists( 'geodirf_excerpt_more' ) ? geodirf_excerpt_more( '' ) : geodir_excerpt_more( '' );
	if ( geodir_utf8_strlen( $excerpt ) > $charlength ) {
		if ( geodir_utf8_strlen( $excerpt_more ) > 0 && geodir_utf8_strpos( $excerpt, $excerpt_more ) !== false ) {
			$excut = - ( geodir_utf8_strlen( $excerpt_more ) );
			$subex = geodir_utf8_substr( $excerpt, 0, $excut );
			if ( $charlength > 0 && geodir_utf8_strlen( $subex ) > $charlength ) {
				$subex = geodir_utf8_substr( $subex, 0, $charlength );
			}
			$out .= $subex;
		} else {
			$subex   = geodir_utf8_substr( $excerpt, 0, $charlength - 5 );
			$exwords = explode( ' ', $subex );
			$excut   = - ( geodir_utf8_strlen( $exwords[ count( $exwords ) - 1 ] ) );
			if ( $excut < 0 ) {
				$out .= geodir_utf8_substr( $subex, 0, $excut );
			} else {
				$out .= $subex;
			}
		}
		$out .= ' ';
		/**
		 * Filter excerpt read more text.
		 *
		 * @since 1.0.0
		 */
		$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
		$out .= '';

	} else {
		if ( geodir_utf8_strlen( $excerpt_more ) > 0 && geodir_utf8_strpos( $excerpt, $excerpt_more ) !== false ) {
			$excut = - ( geodir_utf8_strlen( $excerpt_more ) );
			$out .= geodir_utf8_substr( $excerpt, 0, $excut );
			$out .= ' ';
			/**
			 * Filter excerpt read more text.
			 *
			 * @since 1.0.0
			 */
			$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
			$out .= '';
		} else {
			$out .= $excerpt;
		}
	}
	$post = $temp_post;

	return $out;
}