我想创建一个具有灵活内容字段的表。
有两个主要问题
如果我在循环外插入表主题代码,则表头将针对每个单个字段(灵活的内容行)重复。
如果我在循环中插入表主题代码,则数据无法正确进入表中。表中仅第一柔性内容行的某些字段在表中。其余的灵活内容行未显示。 (除了第一行,该表也为空。)
如何制作一个带有一个标题的表并获得所有灵活内容行及其字段以表形式正确显示?
编辑:以下是转发器域代码。我已经移到中继器字段。
<?php if ( have_rows( 'pokemon_level_up' ) ) : ?>
<table>
<caption>รายละเอียดท่า</caption>
<thead>
<tr>
<th scope="col">เลเวล</th>
<th scope="col">ท่า</th>
<th scope="col">ชนิด</th>
<th scope="col">ประเภท</th>
<th scope="col">ความแรง</th>
<th scope="col">ความแม่นยำ</th>
<th scope="col">PP</th>
<th scope="col">% เอฟเฟกที่สอง</th>
</tr>
</thead>
<?php while ( have_rows( 'pokemon_level_up' ) ) : the_row(); ?>
<?php $move_id = get_sub_field('pokemon_select_move'); ?>
<tr>
<td data-label="เลเวล"><?php the_sub_field( 'pokemon_level' ); ?></td>
<td data-label="ท่า"><?php echo '<a href="'.get_permalink( $move_id ).'">'.get_the_title( $move_id ).'</a>'; ?></td>
<td data-label="ชนิด"><?php $move_type = get_field( 'move_type', $move_id ); ?>
<?php if ( $move_type ) { ?>
<img src="<?php echo $move_type['url']; ?>" alt="<?php echo $move_type['alt']; ?>" />
<?php } ?></td>
<td data-label="ประเภท"><?php $move_category = get_field( 'move_category', $move_id ); ?>
<?php if ( $move_category ) { ?>
<img src="<?php echo $move_category['url']; ?>" alt="<?php echo $move_category['alt']; ?>" />
<?php } ?></td>
<td data-label="ความแรง"><?php the_field( 'move_power', $move_id ); ?></td>
<td data-label="ความแม่นยำ"><?php the_field( 'move_accuracy', $move_id ); ?></td>
<td data-label="PP"><?php the_field( 'move_pp', $move_id ); ?></td>
<td data-label="% เอฟเฟกที่สอง"><?php the_field( 'move_secondary_effect', $move_id ); ?></td>
</tr>
<tr>
<td colspan="8"><?php the_field( 'move_description', $move_id ); ?></td>
</tr>
</table>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
这是原始表源代码https://codepen.io/AllThingsSmitty/pen/MyqmdM
实际上,我本可以使用转发器字段。我从此https://www.youtube.com/watch?v=uRVslHJR9to]中有了一个主意
所以,我选择了灵活的内容,而不是转发器字段。
您能帮我修复代码吗?还是应该使用转发器字段? (如果它可以起到与该特定YouTube视频中所讲授的相同的作用。)
谢谢!
我想创建一个具有灵活内容字段的表。有两个主要问题,如果我在循环外插入表主题代码,则表头会针对每个字段重复出现(灵活...
所有内容将在while循环内重复。