【发布时间】:2022-01-07 20:15:14
【问题描述】:
不再支持我从 Internet 粘贴的这个旧 php 脚本。 create_function 不再有效,我想替换它。但是我无法找到现代解决方案。我的 PHP 技能太糟糕了,甚至无法理解它过去是如何工作的。有谁知道快速修复?我将不胜感激!
//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
'$the_template',
'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
return $the_template;' )
);
【问题讨论】:
标签: php deprecated create-function