http://www.advancedcustomfields.comプラグインを使用して、Wordpressでカスタムフィールドを作成しています。私は特にリピーターフィールド機能を使用しています。
1つのページに、行数に制限のないリピーターがあります。すべてのデータをエコーアウトする通常の方法は次のとおりです。
<?php $counter = 1; if(get_field('step_by_step_training')): ?>
<?php while(the_repeater_field('step_by_step_training')): ?>
<p class="training-<?php echo $counter; ?>"><?php the_sub_field('introduction'); ?></p>
<?php $counter++; endwhile; ?>
<?php endif; ?>
次のボタンを押すと次のデータ行が表示されるので、一度に1行のデータを表示することはできますか?一度に1行のデータのみを表示したいので、行1が最初に表示されている場合、次をクリックすると行1が非表示になり、行2が表示されます。基本的にステップバイステップのプロセスを作成します。
最終的には、ユーザーがデータを送信できるようにフォームを含めたいと思います。
アップデート:
<form class="form" method="POST" action="<?php the_permalink(); ?>">
<?php $counter = 1; if(get_field('step_by_step_training')): ?>
<?php while(the_repeater_field('step_by_step_training')): ?>
<div class="form-row">
<p class="training"><?php echo the_sub_field('introduction'); ?></p>
<button class="next">Next Form Element</button>
</div>
<?php $counter++; endwhile; ?>
<?php endif; ?>
</form>
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
// hide all form-rows, but not the first one
$('.form-row').not(':first').hide();
$('button.next').click(function(e) {
// prevent the next buttons from submitting the form
e.preventDefault();
// hide this form-row, and show the next one
$(this).parent('div.form-row').hide().next('div.form-row').show();
});
});
});
</script>