Support Forum
Support › Meta Box Builder › Display text list in the frontend
Good evening, I have a question of how to create and show a text list to the table below. In it I own variations of fields, each of these variations would be fields to be filled. How do I proceed?
<div class="indices">
<span>2015</span>
<img src="files/img/servicos/base-tabela.png" alt="" />
<ul>
<li style="width:115px;">Março</li>
<li style="width: 114px;">0,38</li>
<li style="width: 116px;">1.258,81</li>
<li style="width: 114px;">0,98</li>
<li style="width: 114px;">0,13</li>
<li style="width: 105px; border:none;">0,36</li>
</ul>
<ul>
<li style="width:115px;">Fevereiro</li>
<li style="width: 114px;">0,22</li>
<li style="width: 116px;">1.253,99</li>
<li style="width: 114px;">0,27</li>
<li style="width: 114px;">0,02</li>
<li style="width: 105px; border:none;">0,50</li>
</ul>
<ul>
<li style="width:115px;">Janeiro</li>
<li style="width: 114px;">0,14</li>
<li style="width: 116px;">1.251,28</li>
<li style="width: 114px;">0,76</li>
<li style="width: 114px;">0,09</li>
<li style="width: 105px; border:none;">0,70</li>
</ul>
<ul class="indice-total">
<li style="width:115px;">Acumulado</li>
<li style="width: 114px;">0,74</li>
<li style="width: 116px;">-</li>
<li style="width: 114px;">2,01</li>
<li style="width: 114px;">0,24</li>
<li style="width: 105px; border:none;">1,56</li>
</ul>
</div>
Hi, agenciaball
To create tabular data with Text List on Meta Box Builder, you can follow this step. I think this picture is worth more than thousand words.
On the Placeholder
column, enter your placeholder for text field, on the Label
column, enter label for text field, and the Default column is the default value of field (only available when not clone).
You can add as many as column (options) which you want.
Please don't forget to check clone
checkbox to create multiple rows.
Then on your code on frontend. You can loop through each rows. I've added this example. Hope it helps 😉
<?php $rows = rwmb_meta( 'my_text_list', array( 'type' => 'text_list' ) ); ?>
<div class="indices">
<span>2015</span>
<img src="files/img/servicos/base-tabela.png" alt="" />
<?php
if ( ! empty( $rows ) ):
foreach ( $rows as $row )
?>
<ul>
<li style="width:115px;"><?php echo $row[0] ?></li>
<li style="width: 114px;"><?php echo $row[1] ?></li>
<li style="width: 116px;"><?php echo $row[2] ?></li>
<li style="width: 114px;"><?php echo $row[3] ?></li>
<li style="width: 114px;"><?php echo $row[4] ?></li>
<li style="width: 105px; border:none;"><?php echo $row[5] ?></li>
</ul>
<?php endforeach;
endif;
?>
</div>
I think there's something wrong in your code, I can not close the tag and make it work
Sorry, the <?php
on the last line in the above example is not necessary, I've removed that, can you remove that and try again?
Btw, can you please update to the latest version of Meta Box Builder, please take a note that you cannot define the Default value when using "clone" with Meta Box Text List. You can define the Meta Box like so and using above code to displaying data:
This form does not work, did the following for her to work:
<?php $rows = rwmb_meta( 'my_text_list', array( 'type' => 'text_list' ) ); ?>
<div class="indices">
<span>2015</span>
<img src="<?php echo site_url().'/';?>files/img/servicos/base-tabela.png" alt="" />
<?php
if ( ! empty( $rows ) ):
foreach ( $rows as $row ){
?>
<ul>
<li style="width:115px;"><?php echo $row[0] ?></li>
<li style="width: 114px;"><?php echo $row[1] ?></li>
<li style="width: 116px;"><?php echo $row[2] ?></li>
<li style="width: 114px;"><?php echo $row[3] ?></li>
<li style="width: 114px;"><?php echo $row[4] ?></li>
<li style="width: 105px; border:none;"><?php echo $row[5] ?></li>
</ul>
<?php }
endif;
?>
<?php $rows = rwmb_meta( 'my_text_list_2', array( 'type' => 'text_list' ) ); ?>
<ul class="indice-total">
<?php
if ( ! empty( $rows ) ):
foreach ( $rows as $row ){
?>
<li style="width:115px;">Acumulado</li>
<li style="width: 114px;"><?php echo $row[0] ?></li>
<li style="width: 116px;"><?php echo $row[1] ?></li>
<li style="width: 114px;"><?php echo $row[2] ?></li>
<li style="width: 114px;"><?php echo $row[3] ?></li>
<li style="width: 105px; border:none;"><?php echo $row[4] ?></li>
</ul>
<?php }
endif;
?>
but from the second call where to find the term "Acumulado" it returns me error
Warning: Invalid argument supplied for foreach() in /home/storage/b/a3/bf/impacto/public_html/wp-content/themes/theme-impacto/single-indices.php on line 46