2
4

1 回答 1

1

WordPress doesn't have the function the_subtitle, but normally all functions starting with the_* will print the value and functions starting with get_the_* will return the value.

Your code entered an infinite loop, because you're calling the_title (should be get_the_title) inside a function that's filtering the_title. It could be fixed removing and adding the filter inside the callback, but that's not needed, as the title is already available.

And also, you're using $post without it being defined, and you don't need it, the post ID is already available too.

Finally, I'm thinking that you're confusing this the_subtitle() function with the value your getting from $subtitle=get_post_meta().

add_filter( 'the_title', 'new_title', 10, 2 );

function new_title( $title, $id ) 
{
    # http://codex.wordpress.org/Conditional_Tags
    if( !is_page_template( 'about.php' )  )
        return $title;

    if( 'page' == get_post_type( $id ) )
        $subtitle = get_post_meta( $id, 'html5blank_webo_subtitle', true );

    if ( $subtitle ) :
        $title = '<div class="page-title">' 
            . $title
            . '</div><h1 class="subtitle">'
            . $subtitle
            . '</h1>';
    else :
        $title = '<h1 class="page-title">' . $title . '</h1>';
    endif;
    return $title;
}
于 2013-09-27T00:17:05.780 回答