Initial commit
This commit is contained in:
43
inc/classes/Excerpt.php
Normal file
43
inc/classes/Excerpt.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Klasa Excerpt
|
||||
*
|
||||
* @link https://krzysztof-turek.com
|
||||
*
|
||||
* @package tylkofotografia.pl
|
||||
* @version 0.2
|
||||
*/
|
||||
|
||||
class Excerpt {
|
||||
|
||||
use Singleton;
|
||||
|
||||
function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public static function improvedExcerpt($text, $length)
|
||||
{
|
||||
global $shortcode_tags;
|
||||
if ('' != $text)
|
||||
{
|
||||
$text = get_the_content('');
|
||||
$text = strip_shortcodes($text);
|
||||
$text = apply_filters('the_content', $text);
|
||||
$text = str_replace('\]\]\>', ']]>', $text);
|
||||
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
|
||||
$text = preg_replace('@<figcaption[^>]*?>.*?</figcaption>@si', '', $text);
|
||||
$text = strip_tags($text);
|
||||
$text = trim($text);
|
||||
$words = explode(' ', $text, $length + 1);
|
||||
|
||||
if (count($words) > $length)
|
||||
{
|
||||
array_pop($words);
|
||||
$text = trim(implode(' ', $words)) . '...';
|
||||
}
|
||||
}
|
||||
$text = preg_replace('/\s\s+/', ' ', $text);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user