行业知识
为不同文章形式选择不同的WordPress文章模板
2026-11-04 09:19:52
来源:互联网转载
在写���章的时候选择不同的文章形式,然后打开文章的时候会调用不同文章形式的模板。比如,文章形式为video ,就调用single-video.php模板,其它文章形式类似,可以添加多个文章样式。
()//为不同文章形式的内容添加不同的single页面add_action('template_include', 'load_single_template');function load_single_template($template) { $new_template =''; // single post template if( is_single() ) { global $post; if ( has_post_format( 'video' )) {// 文章形式为video $new_template = locate_template(array('single-video.php' ));// 就调用single-video.php模板 } if ( has_post_format( 'image' )) {// 文章形式为image $new_template = locate_template(array('single-image.php' ));// 就调用ssingle-image.php模板 }// 这里可以添加其他文章形式的模板 } return (''!= $new_template) ? $new_template : $template;} 将以上代码添加到functions.php文件中即可。
原文
()https://www.zhanyes.com/code/5038.html