1

谁能告诉我如何使用 add_filter 函数来确定页面的 plugin_dir_path ?

当我使用 get_post_type() 为我的 movie_reviews 设置一个寺庙时,没有问题但我不知道如何在无 register_post_type 上使用该函数。

我喜欢在 URL www.domain.com/user_profile 和表单 action action="search_result" 上使用自定义页面,但我不知道这在无 register_post_type 上是如何工作的

add_filter( 'template_include','include_template_function', 1 );

function include_template_function( $template_path ) {

    if ( get_post_type() == 'movie_reviews' ) {
        $template_path = plugin_dir_path( __FILE__ ) .'/single-movie_reviews.php';
    }
    if ( ....... == 'search_sesult' ) {
        $template_path = plugin_dir_path( __FILE__ ) .'/movie-searchresult_reviews.php';
    }
    if ( ....... == 'user_profile' ) {
        $template_path = plugin_dir_path( __FILE__ ) .'/user_profile.php';
    }   


    return $template_path;
}
4

1 回答 1

0

您可以为此使用条件标签

例如:

add_filter( 'template_include','include_template_function', 1 );

function include_template_function( $template_path ) {

    if( is_search() ) 
        $template_path = plugin_dir_path( __FILE__ ) .'/movie-searchresult_reviews.php';

    if( is_author() ) 
        $template_path = plugin_dir_path( __FILE__ ) .'/user_profile.php';


    return $template_path;
}
于 2013-01-21T00:29:45.583 回答