Timber\Post::get_preview PHP Метод

get_preview() публичный Метод

If there's a tag it will use that to mark where to pull through.
public get_preview ( integer $len = 50, boolean $force = false, string $readmore = 'Read More', boolean | string $strip = true, string $end = '…' ) : string
$len integer The number of words that WP should use to make the tease. (Isn't this better than [this mess](http://wordpress.org/support/topic/changing-the-default-length-of-the_excerpt-1?replies=14)?). If you've set a post_excerpt on a post, we'll use that for the preview text; otherwise the first X words of the post_content
$force boolean What happens if your custom post excerpt is longer then the length requested? By default (`$force = false`) it will use the full `post_excerpt`. However, you can set this to true to *force* your excerpt to be of the desired length
$readmore string The text you want to use on the 'readmore' link
$strip boolean | string true for default, false for none, string for list of custom attributes
$end string The text to end the preview with (defaults to ...)
Результат string of the post preview
    public function get_preview($len = 50, $force = false, $readmore = 'Read More', $strip = true, $end = '…')
    {
        $text = '';
        $link = '';
        $trimmed = false;
        $last_p_tag = null;
        if (isset($this->post_excerpt) && strlen(trim($this->post_excerpt))) {
            if ($force) {
                $text = TextHelper::trim_words($this->post_excerpt, $len, false);
                $trimmed = true;
            } else {
                $text = $this->post_excerpt;
            }
        }
        if (!strlen($text) && preg_match('/<!--\\s?more(.*?)?-->/', $this->post_content, $readmore_matches)) {
            $pieces = explode($readmore_matches[0], $this->post_content);
            $text = $pieces[0];
            if ($force) {
                $text = TextHelper::trim_words($text, $len, false);
                $trimmed = true;
            }
            $text = do_shortcode($text);
        }
        if (!strlen($text)) {
            $text = TextHelper::trim_words($this->get_content(), $len, false);
            $trimmed = true;
        }
        if (!strlen(trim($text))) {
            return trim($text);
        }
        if ($strip) {
            $allowable_tags = is_string($strip) ? $strip : null;
            $text = trim(strip_tags($text, $allowable_tags));
        }
        if (strlen($text)) {
            $text = trim($text);
            $last = $text[strlen($text) - 1];
            if ($last != '.' && $trimmed) {
                $text .= $end;
            }
            if (!$strip) {
                $last_p_tag = strrpos($text, '</p>');
                if ($last_p_tag !== false) {
                    $text = substr($text, 0, $last_p_tag);
                }
                if ($last != '.' && $trimmed) {
                    $text .= $end . ' ';
                }
            }
            $read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
            if ($readmore && isset($readmore_matches) && !empty($readmore_matches[1])) {
                $link = ' <a href="' . $this->link() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>';
            } elseif ($readmore) {
                $link = ' <a href="' . $this->link() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>';
            }
            $text .= apply_filters('timber/post/get_preview/read_more_link', $link);
            if (!$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p '))) {
                $text .= '</p>';
            }
        }
        return trim($text);
    }