所以我试图只打印一些标签,每个循环有四个标签.
所以我总是试图循环并在每个标签上打印一次标签.
第二步是每个循环打印四个标签.
为了更好地解释这里有一些图片.
这是我的代码
<?php foreach ($formAttributes as $key => $value):?>
<?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>"
<?php endforeach; ?>>
<?php endif ?><?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?>
<?php foreach($questions as $q => $question): /* @var $question WpTesting_Model_Question */ ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
<?php echo $question->getTitle() ?>
<?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?>
<?php foreach($question->buildAnswers() as $a => $answer): /* @var $answer WpTesting_Model_Answer */ ?>
<?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?>
data-errormessage="<?php echo $isMultipleAnswers
? __('Please select at least one answer.', 'wp-testing')
: __('Please choose only one answer.', 'wp-testing') ?>"
<?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?>
name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" />
<?php echo $answer->getTitleOnce() ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?>
<?php foreach($hiddens as $name => $value): ?><?php endforeach ?>
解决方法:
这绝不是复制粘贴解决方案.您的代码中有些变量我不知道它们包含什么,但这应该是解决方案的潜在想法.基本上,期望的结果是数据的“表”.您是否使用表格或div来构建HTML结构.您可以使用诸如bootstrap或foundation或其他CSS框架提供的布局.此示例仅使用表来提供结构.您需要将答案标签绘制到容器(如数组)中,以便在表头中进行迭代.然后,您可以简单地使用输入呈现每个答案,而不关心是否在每次迭代时打印它.希望这可以帮助!
/**
* @var array $answerLabels
* @var WpTesting_Model_Question[] $questions
*/
?>
= $label ?>
= $question->getTitle() ?><?php foreach ($question->buildAnswers() as $index => $answer):
$answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId();
?>
id="= $answerId ?>"
data-errormessage="= $isMultipleAnswers
? __('Please select at least one answer.', 'wp-testing')
: __('Please choose only one answer.', 'wp-testing') ?>"
required="required"
aria-required="true"
name="= $answerIdName ?>[= $answerIndex ?>]"
value="= $answer->getId() ?>"/>
标签:php,wordpress,plugins
来源: https://codeday.me/bug/20190828/1753821.html