Belirli bir kategori için özel tek şablon tanımlamak

Prpjenizde belirli bir kategorinin farklı bir single post template kullanmasnı isteyebilirsiniz. Bunu yapmanın en elverişli yolu aşağıdaki gibidir:

// Custom single template by category
// https://halgatewood.com/wordpress-custom-single-templates-by-category

add_filter(‘single_template’, ‘check_for_category_single_template’);
function check_for_category_single_template( $t )
{
foreach( (array) get_the_category() as $cat )
{
if ( file_exists(STYLESHEETPATH . “/single-category-{$cat->slug}.php”) ) return STYLESHEETPATH . “/single-category-{$cat->slug}.php”;
if($cat->parent)
{
$cat = get_the_category_by_ID( $cat->parent );
if ( file_exists(STYLESHEETPATH . “/single-category-{$cat->slug}.php”) ) return STYLESHEETPATH . “/single-category-{$cat->slug}.php”;
}
}
return $t;
}

Yayım tarihi
Genel olarak sınıflandırılmış

Yorum Gönderin

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir