php - If Statement Inside Html -
i trying use if statement if variable $credit not empty. however, parse error. please syntax?
$credit = get_field('fl_credit', $image['id']); return '<div class="kalim"><img title="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" alt="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" src="' . $image['url'] . '" /><div class="kalca">' . $image['caption'] . '</div>' . if($credit) {'<div class="kalcr">credit:' . $credit . '</div></div>' };
without knowing error, suggest short if, so:
$credit = get_field('fl_credit', $image['id']); return '<div class="kalim"><img title="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" alt="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" src="' . $image['url'] . '" /><div class="kalca">' . $image['caption'] . '</div>' . (!empty($credit) ? '<div class="kalcr">credit:' . $credit . '</div></div>': '' ) ; you can see more here
Comments
Post a Comment