also am wandering if i could create a lop for the info.
so i could put several names in the employee_name filed? Seems like it should work?
could i get some advice on how to do this or get pointed to a tutorial on it?
thx
D
<?php
if(get_field('employee_name')){
echo'<table class="gAndE">'; # Move this OUTSIDE the loop, we only need rows
# Grab the variables
$name = get_field('employee_name');
$deskPhone = get_field('desk_phone');
# Loop through each
# Note the <?=@ symbol is used to hide possible warnings when $name[$i] is empty
for($i = 0; $i < count($name); $i++): ?>
<tr>
<td><?=@ $name[$i] ?></td>
<td><?=@ $deskPhone[$i] ?></td>
</tr>
<?php endforeach;
echo'</table>';
}
You can use echo statements if you like, but this is a little cleaner.
Say the tags don’t seem to be closing appropriately. i tried adding an extra php delimiter but it seems incorrect, could you please advise?
For example you have <?php endforeach; do you meant for that to be closed elsewhere?
thx
D
At the very end of what I posted, so the complete code should be:
<?php
if(get_field('employee_name')){
echo'<table class="gAndE">'; # Move this OUTSIDE the loop, we only need rows
# Grab the variables
$name = get_field('employee_name');
$deskPhone = get_field('desk_phone');
# Loop through each
# Note the <?=@ symbol is used to hide possible warnings when $name[$i] is empty
for($i = 0; $i < count($name); $i++): ?>
<tr>
<td><?=@ $name[$i] ?></td>
<td><?=@ $deskPhone[$i] ?></td>
</tr>
<?php endforeach;
echo'</table>';
} ?>
no. i had taken that into account and figured you just assumed i’d put the closing tag in. So did.
<?php
if(get_field('employee_name')){
echo'<table class="gAndE">'; # Move this OUTSIDE the loop, we only need rows
# Grab the variables
$name = get_field('employee_name');
$deskPhone = get_field('desk_phone');
# Loop through each
# Note the <?=@ symbol is used to hide possible warnings when $name[$i] is empty
for($i = 0; $i < count($name); $i++): ?>
<tr>
<td><?=@ $name[$i] ?></td>
<td><?=@ $deskPhone[$i] ?></td>
</tr>
<?php endforeach;
echo'</table>';
} ?>
gets me error
Parse error: syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in C:\xampp\htdocs\cdi\wp-content\themes\cdi_oregon\employeeList.php on line 37
i really see no reason for it though.
It is inside the loop, everything looks ok.
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
?>
<?php
if(get_field('employee_name')){
echo'<table class="gAndE">'; # Move this OUTSIDE the loop, we only need rows
# Grab the variables
$name = get_field('employee_name');
$deskPhone = get_field('desk_phone');
# Loop through each
# Note the <?=@ symbol is used to hide possible warnings when $name[$i] is empty
for($i = 0; $i < count($name); $i++): ?>
<tr>
<td><?=@ $name[$i] ?></td>
<td><?=@ $deskPhone[$i] ?></td>
</tr>
<?php endforeach;
echo'</table>';
} ?>
<?php endwhile; ?>
<?php cdi_oregon_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
Thank you Oz. that was great. And just about there. It only gives the first letter of the name & first number of the phone however.
Which makes not sense as in the array you are asking for the full field. I don’t see anywhere in the code why it would only do that.
D