Link to home
Start Free TrialLog in
Avatar of livewirewebsolutions
livewirewebsolutions

asked on

Shorten a simple php code

How can I shorten the code below.  It's just displaying 3 lines of text from form fields completed by the client.  It currently displays as:

area1
area2
area3

and I want it to display as area1, area2, area3

<?php $field = wpbdp_get_form_field( 11 );
echo $field->display( $listing_id ); ?>

<?php $field = wpbdp_get_form_field( 13 );
echo $field->display( $listing_id ); ?>

<?php $field = wpbdp_get_form_field( 12 );
echo $field->display( $listing_id ); ?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This may be a CSS issue, not a PHP issue.  What is the contents of $field->display() in these cases?  You can use the browser "view source" to get a correct view of the data.

This is Wordpress, right?
Avatar of livewirewebsolutions
livewirewebsolutions

ASKER

Yes, WP.

It seems to wrap each one in a div and a span tag.
What is the contents of $field->display() in these cases?
Here's the page:
http://www.thebrontevillager.ca/our-advertisers/gliding-shelf-solutions/
pw is demo5

It's the address on the right side.

Also, Is putting
echo $field->display( $listing_id ); ?>

Open in new window

every time, redundant.
Avatar of Steve Bink
Here's one optimization:
<div class="wpbdp-form-fields">
<?php 
  /* need different numbers?  just change the array you pass into the loop */
  for ([11,13,12] as $val) {   
    $field = wpbdp_get_form_field( $val )->display($listing_id);
  }
?></div>

Open in new window

With this, you can specify how to display this information by targeting the CSS selector "div.wpbdp-form-fields" and its children.  For example:
div.wpbdp-form-fields > * { display: inline-block; }

Open in new window

that method gives me an error:

Parse error: syntax error, unexpected 'as' (T_AS), expecting ';' in /home4/frazier/public_html/thebrontevillager.ca/wp-content/themes/Divi-Child/businessdirectory-listing.tpl.php on line 8

Line 8 is below code:
for ([12,13,11,10] as $val) {   

Open in new window

SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this is above my head.  just added the foreach and nothing displays.
Try this change and post what you see in the HTML:
<div class="wpbdp-form-fields">
<?php 
  /* need different numbers?  just change the array you pass into the loop */
  foreach ([12,13,11,10] as $val) {   
    echo "<div>Display value $val</div>";
    wpbdp_get_form_field( $val )->display($listing_id);  
  }
?></div>

Open in new window

Cool, that has potential.

Display value 12
Display value 13
Display value 11
Display value 10
And what is in the actual HTML?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're right slick812.  I do need to do more research on php.  FYI - I posted the pw to the link above at the very beginning.  Thanks for everyones help.  The last code seemed to work.