typecho different classification methods calling different templates

category.php is typecho category page template file, typecho category list page of the unified template file called, then the need to achieve a different category page using a different display site how to do? The method can be classified by custom or template syntax to use is to determine the category page.

Method One: Custom Category templates

The different categories of template files to classify abbreviated name names, such as default.php, technology.php (abbreviated name please in the background - Management - category view), and then create a named template category in the current directory folder, the different categories of template files into that folder, so that when the category page, it will automatically call the corresponding classification classification template abbreviated name.

Method Two: Use IS grammar page judgment in the template file

1, abbreviated call default.php named default template file classification, classify the remaining call other.php template file

1
2
3
4
5
6
7
<?php 
	if($this->is('category','default')){
		$this->need('default.php');
	}else{
		$this->need('other.php');
	}
?>

2, abbreviated classification named default template file default.php call, call technology.php template file as a thumbnail of technology, and so on, the rest of the call other.php template file

1
2
3
4
5
6
7
8
9
<?php 
	if($this->is('category','default')){
		$this->need('default.php');
	}elseif($this->is('category','technology')){
		$this->need('technology.php');
	}else{
		$this->need('other.php');
	}
?>

3, thumbnails default, technology call default.php file, the rest of the call other.php template file

1
2
3
4
5
6
7
8
9
10
<?php 
$slugArray = array('default','technology');
foreach($slugArray as $slug){
	if($this->is('category',$slug)){
		$this->need('default.php');
	}else{
		$this->need('other.php');
	}
}
?>

The above three types is a commonly used method, there is a need bloggers can draw inferences!

Guess you like

Origin www.cnblogs.com/zgpz123/p/11964193.html