LoginSignup
0
0

More than 5 years have passed since last update.

【覚書】WP:親カテゴリのテンプレートを小カテゴリに!

Posted at

functions.phpにこれをプラス

add_filter( 'category_template', 'my_category_template' );

function my_category_template( $template ) {
    $category = get_queried_object();
    if ( $category->parent != 0 &&
        ( $template == "" || strpos( $template, "category.php" ) !== false ) ) {
        $templates = array();
        while ( $category->parent ) {
            $category = get_category( $category->parent );
            if ( !isset( $category->slug ) ) break;
            $templates[] = "category-{$category->slug}.php";
            $templates[] = "category-{$category->term_id}.php";
        }
        $templates[] = "category.php";
        $template = locate_template( $templates );
    }
    return $template;
}

http://studio-freetown.com/post-783/

参考にしました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0