我在我的WordPress主题中有一个选项面板,里面有几个文本字段。例如:项目名称、项目描述、Twitter用户名等。
case 'text':
$val = $value['std'];
$std = get_option($value['id']);
if ( $std != "") { $val = $std; }
$output .= '<input class="" maxlength="12" name=""'. $value['id'] .'" id="'. $value['id'] .'" type="'. $value['type'] .'" value="'. $val .'" />';
break;如上面的代码所示...我目前的文本字段的最大长度为12,但我希望每个文本字段的最大长度都不同。我该怎么做呢?
文本字段的输入ID是mytheme_projectitle1、mytheme_projectitle2、mytheme_projectitle3、mytheme_twitterusername等。我没有为它们中的任何一个提供输入类,只有ID。
发布于 2012-11-11 01:16:15
您可以使用$value['id']访问每个元素的id,这在代码中是显而易见的。使用它来派生最大长度,例如这样:
case 'text':
// Overrides for the default value of maxlength
$maxlengths = array(
'mytheme_projecttitle1' => 10,
'mytheme_projecttitle2' => 20,
);
// If there is an override value use it; otherwise use the default of 12
$maxlen = isset($maxlengths[$value['id']]) ? $maxlengths[$value['id']] : 12;
$val = $value['std'];
$std = get_option($value['id']);
if ( $std != "") { $val = $std; }
$output .= '<input class="" maxlength="'.$maxlength.'"..."; // the rest as beforehttps://stackoverflow.com/questions/13324142
复制相似问题