博客摘录在wordpress中

I've purchased a theme and the blog excerpt works fine on their demo site, but not on my website's blog overview page. this is the code I found, but this is the wordpress post-template.php The theme does not have any blog settings which leads me to think it's a wordpress issues?

Hopre someone can help,

Many thanks!

P.S. Php newbie so please explain how I can fix this.

function get_the_excerpt( $deprecated = '' ) {
    if ( !empty( $deprecated ) )
        _deprecated_argument( __FUNCTION__, '2.3' );

    $post = get_post();
    if ( empty( $post ) ) {
        return '';
    }

    if ( post_password_required() ) {
        return __( 'There is no excerpt because this is a protected post.' );
    }

    /**
     * Filter the retrieved post excerpt.
     *
     * @since 1.2.0
     *
     * @param string $post_excerpt The post excerpt.
     */
    return apply_filters( 'get_the_excerpt', $post->post_excerpt );
}


/**
 * Whether post has excerpt.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @return bool
 */
function has_excerpt( $id = 0 ) {
    $post = get_post( $id );
    return ( !empty( $post->post_excerpt ) );
}

/**
 * Display the classes for the post div.
 *
 * @since 2.7.0
 *
 * @param string|array $class One or more classes to add to the class list.
 * @param int|WP_Post $post_id Optional. Post ID or post object.
 */
function post_class( $class = '', $post_id = null ) {
    // Separates classes with a single space, collates classes for post DIV
    echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
}

By default the_excerpt() return the text in the excerpt field. Though you can use a filter to change what it returns:

add_filter( 'get_the_excerpt', 'my_custom_excerpt' );

It will trigger this function when the_excerpt() will be called:

function my_custom_excerpt($excerpt) {
    if(empty($excerpt)) {
        return get_custom_excerpt();
    } else {
        return $excerpt;
    }
}

That way a custom excerpt will be used if the excerpt field is empty. Here is the code for get_custom_excerpt (it will do a "smart" ceasure):

function print_excerpt($length)
{ 
    global $post;
    $text = $post->post_excerpt;
    if ( '' == $text ) {
            $text = get_the_content('');
            $text = apply_filters('the_content', $text);
            $text = str_replace(']]>', ']]>', $text);
    }
    $text = strip_shortcodes($text);
    $text = strip_tags($text, '<a>'); // change this to the tags you want to keep

    if (preg_match('/^.{1,'.$length.'}\b/s', $text, $match))
        $text = $match[0];
    $excerpt = reverse_strrchr($text, array('.','!'), 1, 100);
    if($excerpt) {
            echo apply_filters('the_excerpt',$excerpt);
    } else {
            echo apply_filters('the_excerpt',$text.'...');
    }
}
function reverse_strrchr($haystack, $needle, $trail, $offset=0)
{
    return strrposa($haystack, $needle, $offset) ? substr($haystack, 0, strrposa($haystack, $needle, $offset) + $trail) : false;
}
// strrpos in Array mode
function strrposa($haystack, $needles=array(), $offset=0)
{
    if(!is_array($needles))
        $needles = array($needles);
    foreach($needles as $query) {
        if(strrpos($haystack, $query, $offset) !== false)
            return strrpos($haystack, $query, $offset);
    }
    return false;
}