Example #1
0
/**
 * Add the text of the post in form of excerpt, full post, and so on.
 *
 * @since 1.18
 * @param array $args The array containing the custom parameters.
 * @return The HTML for the text of the post.
 * @uses pis_break_text()
 * @uses pis_more_arrow()
 */
function pis_the_text($args)
{
    $defaults = array('excerpt' => 'excerpt', 'pis_query' => '', 'exc_length' => 20, 'the_more' => __('Read more…', 'posts-in-sidebar'), 'exc_arrow' => false);
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    $output = '';
    /*
    	"Full content"   = the content of the post as displayed in the page.
    	"Rich content"   = the content with inline images, titles and more (shortcodes will be executed).
    	"Content"        = the full text of the content, whitout any ornament (shortcodes will be stripped).
    	"More excerpt"   = the excerpt up to the point of the "more" tag (inserted by the user, shortcodes will be stripped).
    	"Excerpt"        = the excerpt as defined by the user or generated by WordPress (shortcodes will be stripped).
    	"Only Read more" = no excerpt, only the Read more link
    */
    switch ($excerpt) {
        case 'full_content':
            /* Filter the post content. If not filtered, shortcodes (and other things) will not be executed.
             * See https://codex.wordpress.org/Function_Reference/get_the_content
             */
            $output .= apply_filters('the_content', get_the_content());
            break;
        case 'rich_content':
            $content = $pis_query->post->post_content;
            // Honor any paragraph break
            $content = pis_break_text($content);
            $output .= apply_filters('pis_rich_content', $content);
            break;
        case 'content':
            // Remove shortcodes
            $content = strip_shortcodes($pis_query->post->post_content);
            // remove any HTML tag
            $content = wp_kses($content, array());
            // Honor any paragraph break
            $content = pis_break_text($content);
            $output .= apply_filters('pis_content', $content);
            break;
        case 'more_excerpt':
            $excerpt_text = strip_shortcodes($pis_query->post->post_content);
            $testformore = strpos($excerpt_text, '<!--more-->');
            if ($testformore) {
                $excerpt_text = substr($excerpt_text, 0, $testformore);
            } else {
                $excerpt_text = wp_trim_words($excerpt_text, $exc_length, '&hellip;');
            }
            $output .= apply_filters('pis_more_excerpt_text', $excerpt_text) . ' ' . pis_more_arrow($the_more, $exc_arrow, false);
            break;
        case 'excerpt':
            /**
             * Check if the Relevanssi plugin is active and restore the user-defined excerpt in place of the Relevanssi-generated excerpt.
             * @see https://wordpress.org/support/topic/issue-with-excerpts-when-using-relevanssi-search
             *
             * @since 1.26
             */
            if (function_exists('relevanssi_do_excerpt') && isset($pis_query->post->original_excerpt)) {
                $pis_query->post->post_excerpt = $pis_query->post->original_excerpt;
            }
            // If we have a user-defined excerpt...
            if ($pis_query->post->post_excerpt) {
                // Honor any paragraph break
                $user_excerpt = pis_break_text($pis_query->post->post_excerpt);
                $output .= apply_filters('pis_user_excerpt', $user_excerpt) . ' ' . pis_more_arrow($the_more, $exc_arrow, false);
            } else {
                // ... else generate an excerpt
                $excerpt_text = strip_shortcodes($pis_query->post->post_content);
                $excerpt_text = wp_trim_words($excerpt_text, $exc_length, '&hellip;');
                $output .= apply_filters('pis_excerpt_text', $excerpt_text) . ' ' . pis_more_arrow($the_more, $exc_arrow, false);
            }
            break;
        case 'only_read_more':
            $excerpt_text = '';
            $output .= apply_filters('pis_only_read_more', $excerpt_text) . ' ' . pis_more_arrow($the_more, $exc_arrow, false);
            break;
    }
    // Close The text
    return $output;
}
Example #2
0
/**
 * Add the text of the post in form of excerpt, full post, and so on.
 *
 * @since 1.18
 * @return The HTML for the text of the post.
 */
function pis_the_text($excerpt, $pis_query, $exc_length, $the_more, $exc_arrow)
{
    /*
    	"Full content" = the content of the post as displayed in the page.
    	"Rich content" = the content with inline images, titles and more (shortcodes will be executed).
    	"Content"      = the full text of the content, whitout any ornament (shortcodes will be stripped).
    	"More excerpt" = the excerpt up to the point of the "more" tag (inserted by the user).
    	"Excerpt"      = the excerpt as defined by the user or generated by WordPress.
    */
    switch ($excerpt) {
        case 'full_content':
            the_content();
            break;
        case 'rich_content':
            $content = $pis_query->post->post_content;
            // Honor any paragraph break
            $content = pis_break_text($content);
            echo apply_filters('pis_rich_content', $content);
            break;
        case 'content':
            // Remove shortcodes
            $content = strip_shortcodes($pis_query->post->post_content);
            // remove any HTML tag
            $content = wp_kses($content, array());
            // Honor any paragraph break
            $content = pis_break_text($content);
            echo apply_filters('pis_content', $content);
            break;
        case 'more_excerpt':
            $excerpt_text = strip_shortcodes($pis_query->post->post_content);
            $testformore = strpos($excerpt_text, '<!--more-->');
            if ($testformore) {
                $excerpt_text = substr($excerpt_text, 0, $testformore);
            } else {
                $excerpt_text = wp_trim_words($excerpt_text, $exc_length, '&hellip;');
            }
            echo apply_filters('pis_more_excerpt_text', $excerpt_text);
            pis_more_arrow($the_more, $exc_arrow);
            break;
        case 'excerpt':
            // If we have a user-defined excerpt...
            if ($pis_query->post->post_excerpt) {
                // Honor any paragraph break
                $user_excerpt = pis_break_text($pis_query->post->post_excerpt);
                echo apply_filters('pis_user_excerpt', $user_excerpt);
            } else {
                // ... else generate an excerpt
                $excerpt_text = strip_shortcodes($pis_query->post->post_content);
                $excerpt_text = wp_trim_words($excerpt_text, $exc_length, '&hellip;');
                echo apply_filters('pis_excerpt_text', $excerpt_text);
            }
            pis_more_arrow($the_more, $exc_arrow);
            break;
    }
    // Close The text
}