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
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 ); ?>
ASKER
Yes, WP.
It seems to wrap each one in a div and a span tag.
It seems to wrap each one in a div and a span tag.
What is the contents of $field->display() in these cases?
ASKER
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
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 ); ?>
every time, redundant.
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>
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; }
ASKER
that method gives me an error:
Parse error: syntax error, unexpected 'as' (T_AS), expecting ';' in /home4/frazier/public_html /thebronte villager.c a/wp-conte nt/themes/ Divi-Child /businessd irectory-l isting.tpl .php on line 8
Line 8 is below code:
Parse error: syntax error, unexpected 'as' (T_AS), expecting ';' in /home4/frazier/public_html
Line 8 is below code:
for ([12,13,11,10] as $val) {
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>
ASKER
Cool, that has potential.
Display value 12
Display value 13
Display value 11
Display value 10
Display value 12
Display value 13
Display value 11
Display value 10
And what is in the actual HTML?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
This is Wordpress, right?