I am trying to use an IF statement if variable $credit is not empty. However, I get a parse error. Could anyone please help with my 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 the error, I suggest do a 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
Check this if it help you
<?php
$credit = get_field('fl_credit', $image['id']);
$return_data = '<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(!empty($credit)){
$return_data .= '<div class="kalcr">Credit:' . $credit . '</div>';
}
$return_data .= '</div>';
return $return_data;
?>
Related
I have a problem with
woocommerce_quantity. Everything works fine now, but woocommerce_quantity appears twice in the frontend. I have already searched various sites and have not yet found a solution to the problem.
Here is my code:
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$current_lang = pll_current_language();
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false ); <-- Here is the quantity i needed.
$html .= '<input type="hidden" name="lightbox_for_products" value="1">';
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
$html .= '<div id="ts_shop_modal_products" class="modal">';
$html .= '<div class="modal-content">';
$html .= '<span class="close">×</span>';
if ( $current_lang == 'de' ) {
$html .= '<button class="button alt"><a style="color: #fff" href="' . wc_get_cart_url() . '">'. pll__( 'Zum Warenkorb' ) .'</a></button><br/><br/>';
$html .= '<button class="button alt"><a style="color: #fff" href="'. get_bloginfo('url') .'/eintrittskartenshop/" >' . pll__( 'Zurück zur Übersicht' ) . '</a></button>';
} else {
$html .= '<button class="button alt"><a style="color: #fff" href="' . wc_get_cart_url() . '">'. pll__( 'Zum Warenkorb' ) .'</a></button><br/><br/>';
$html .= '<button class="button alt"><a style="color: #fff" href="'. get_bloginfo('url') .'/en/shop" >' . pll__( 'Zurück zur Übersicht' ) . '</a></button>';
}
$html .= '</div>';
$html .= '</div>';
}
In frontend it looks like this:
I use php ver. 7.1.0 and now I have problem
Fatal error: Switch statements may only contain one default clause in
/icore.php on line 477
Here's the code:
476 case 'html':
477 default:
478 echo $std;
479
480 if ( $desc != '' )
481 echo '<br /><span class="description">' . $desc . '</span>';
482
483 break;
Can I fix it?
Full code for switch:
switch ( $type ) {
case 'heading':
echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';
foreach ( $choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
echo '</select>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'radio':
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
if ( $i < count( $options ) - 1 )
echo '<br />';
$i++;
}
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'text':
default:
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'html':
default:
echo $std;
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'upload':
default:
echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';
if ( $desc != '' )
echo '
<span class="description">' . $desc . '</span>';
echo '<div class="upload-img-preview">';
if (esc_attr( $options[$id] <> '')) {
echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
}
echo '</div>';
break;
case 'slide':
if ( $desc != '' )
echo '<span class="description' . $field_class . '">' . $desc . '</span>';
echo '<br /><span id="slides-details-button"></span>';
echo '<ul id="slideshow_list">';
if ( $options['slider'] <> '' ) {
$slides = array();
foreach ($options[$id]['title'] as $k => $v) {
$slides[] = array(
'title' => $v,
'link' => $options[$id]['link'][$k],
'caption' => $options[$id]['caption'][$k],
'image' => $options[$id]['image'][$k]
);
}
$i = 1;
foreach ($slides as $slide) {
echo '<li class="slide">';
echo '<a class="editslideimage">edit</a>';
echo '<div class="image-details slidedetails">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['title'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['link'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
' . __( 'Upload','InterStellar' ) . '';
echo '<a class="doneslideimage">Done</a>';
echo '</div>';
echo '<div class="clear"></div><div class="upload-img-preview">';
if ( $slide['image'] != "" )
{
echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
}
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
echo '</li>';
$i++;
}
} else {
$i = 1;
echo '<li class="slide">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
' . __( 'Upload', 'icore' ) . '';
echo '<div class="clear"></div><div class="upload-img-preview">';
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
echo '</li>';
}
echo '</ul>';
break;
}
}
Is this enought?
You can not use a case statement inside a case. Try this corrected code
switch ( $type ) {
case 'heading':
echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';
foreach ( $choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
echo '</select>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'radio':
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
if ( $i < count( $options ) - 1 )
echo '<br />';
$i++;
}
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'text':
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'html':
echo $std;
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
default:
echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';
if ( $desc != '' )
echo '
<span class="description">' . $desc . '</span>';
echo '<div class="upload-img-preview">';
if (esc_attr( $options[$id] <> '')) {
echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
}
echo '</div>';
break;
case 'slide':
if ( $desc != '' )
echo '<span class="description' . $field_class . '">' . $desc . '</span>';
echo '<br /><span id="slides-details-button"></span>';
echo '<ul id="slideshow_list">';
if ( $options['slider'] <> '' ) {
$slides = array();
foreach ($options[$id]['title'] as $k => $v) {
$slides[] = array(
'title' => $v,
'link' => $options[$id]['link'][$k],
'caption' => $options[$id]['caption'][$k],
'image' => $options[$id]['image'][$k]
);
}
$i = 1;
foreach ($slides as $slide) {
echo '<li class="slide">';
echo '<a class="editslideimage">edit</a>';
echo '<div class="image-details slidedetails">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['title'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['link'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
' . __( 'Upload','InterStellar' ) . '';
echo '<a class="doneslideimage">Done</a>';
echo '</div>';
echo '<div class="clear"></div><div class="upload-img-preview">';
if ( $slide['image'] != "" )
{
echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
}
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
echo '</li>';
$i++;
}
} else {
$i = 1;
echo '<li class="slide">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
' . __( 'Upload', 'icore' ) . '';
echo '<div class="clear"></div><div class="upload-img-preview">';
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
echo '</li>';
}
echo '</ul>';
break;
}
}
How do I get this example echo image to work single and double?
data-mean="<?php
echo
'<div>' . $k["auto_ans"][$i] . '</div>' .
'<div><img src=' . $k["auto_image"][$i] . '></div>' .
'<div><img src=' . $k["auto_image2"][$i] . '></div>'; ?>"
I want it to output:
data-mean="<div>AAAA</div><div><img src='aaa.jpg'></div><div><img src='bbb.jpg></div>"
You should put quotes around SRC prop like this :
data-mean="<?php
echo
'<div>' . $k["auto_ans"][$i] . '</div>' .
'<div><img src=\'' . $k["auto_image"][$i] . '\'></div>' .
'<div><img src=\'' . $k["auto_image2"][$i] . '\'></div>'; ?>"
I have this code:
$limit = 8;
for($x=0;$x<$limit;$x++) {
$title = substr(str_replace(' & ', ' & ', $feed[$x]['title']), 0, 60);
$link = $feed[$x]['link'];
$description = substr(preg_replace('/\<a.*/', '', $feed[$x]['desc']),0 , 120) . " ... "; //$feed[$x]['desc'];
$image = preg_replace('/\?w.*/', '', $feed[$x]['image']);
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<div class="blog-item item col-md-4' . $rowOpen . '"><img src="' . $image . '"><div class="blog-item-info"><div class="title"><h3>'. $title . '</h3></div><div class="date">' . $date . '</div><div class="preview"><p>'. $description .'</p></div><button class="read-more">Read More</button></div></div></div>';
/*echo '<p><strong>'.$title.'</strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo $image;
//echo '<p>'.$description.'</p>';*/
}
What I want to do is I want every three echos to be wrapped in a
<div class="row"></div>
So I want it to look like this:
<div class="row">
echo '<div class="blog-item item col-md-4' . $rowOpen . '"><img src="' . $image . '"><div class="blog-item-info"><div class="title"><h3>'. $title . '</h3></div><div class="date">' . $date . '</div><div class="preview"><p>'. $description .'</p></div><button class="read-more">Read More</button></div></div></div>';
echo '<div class="blog-item item col-md-4' . $rowOpen . '"><img src="' . $image . '"><div class="blog-item-info"><div class="title"><h3>'. $title . '</h3></div><div class="date">' . $date . '</div><div class="preview"><p>'. $description .'</p></div><button class="read-more">Read More</button></div></div></div>';
echo '<div class="blog-item item col-md-4' . $rowOpen . '"><img src="' . $image . '"><div class="blog-item-info"><div class="title"><h3>'. $title . '</h3></div><div class="date">' . $date . '</div><div class="preview"><p>'. $description .'</p></div><button class="read-more">Read More</button></div></div></div>';
</div><!-- end .row -->
I have tried multiple things but I cannot get it to work. What should I do?
You can check if the $x modulo 3 is 0, then you need a new row. like this:
echo '<div class="row">';
$limit = 8;
for($x=0;$x<$limit;$x++) {
$title = substr(str_replace(' & ', ' & ', $feed[$x]['title']), 0, 60);
$link = $feed[$x]['link'];
$description = substr(preg_replace('/\<a.*/', '', $feed[$x]['desc']),0 , 120) . " ... ";
$image = preg_replace('/\?w.*/', '', $feed[$x]['image']);
$date = date('l F d, Y', strtotime($feed[$x]['date']));
// if x is devidable by 3, start a new row
if($x % 3 == 0 && $x != 0) echo '</div><div class="row">';
echo '<div class="blog-item item col-md-4' . $rowOpen . '"><img src="' . $image . '"><div class="blog-item-info"><div class="title"><h3>'. $title . '</h3></div><div class="date">' . $date . '</div><div class="preview"><p>'. $description .'</p></div><button class="read-more">Read More</button></div></div>';
}
echo '</div>';
note that you are also closing a div to much in your echo ;)
From an array I start for each entry a function with a argument from the array (its friends from facebook). The function returns either 0 or a number bigger than 0. So at the moment, it justs displays it all mixed up, but I want it to show first all entries which get the result bigger than 0 from the function and then all, which are 0. I've no idea, how to do this.
This is my current code.
foreach ($friends as $key=>$value) {
//removed unimportant things
$friendresult = friendscore($id = $fvalue[id]);
if ($friendresult == "0") {
echo '<li>';
echo '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<b>Invite</b>';
echo '</a>';
echo '</li>';
}
if ($friendresult !=="0"){
echo '<li>';
echo '<a class="box">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<div class="totaltext">Score:'.$friendresult. '</div>';
echo '</a>';
echo '</li>';
}}
Edit: Found solution. Sometimes its too simple.
if ($friendresult == "0") {
$friend.= '<li>';
$friend.= '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
$friend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$friend.= '<label>' . $fvalue[name] . '</label>';
$friend.= '<b>Invite</b>';
$friend.= '</a>';
$friend.= '</li>';
}
if ($friendresult !="0"){
$nofriend.= '<li>';
$nofriend.= '<a class="box">';
$nofriend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$nofriend.= '<label>' . $fvalue[name] . '</label>';
$nofriend.= '<div class="totaltext">Score:'.$friendresult. '</div>';
$nofriend.= '</a>';
$nofriend.= '</li>';
}
echo $friend.$nofriend;