这里实现不同的分类页调用不同的文章页模版。
这里需要掌握的方法:
get_template_part($slug,$name);
作用:自定义模版文件调用函数,即加载一个制定的模版到另一个模版里面。如果没有指定模版,那么函数就会调用通用模版来显示。其中:- $slug:通用模版名(必须)。
- $name:指定模版名。
php
//加载content-$name.php,模版文件,如果文件不存在,则加载content.php文件。
get_template_part('content',$name);
get_the_category($id);
作用:获取当前文章的分类。参数是当前文章的ID。get_the_ID();
作用:获取当前文章的ID,同$post->ID
。