I have this if else statement that gives me an <img src=""..../>
element as result. My problem is that i want the statement to give me a result as <li><img src=""..../></li>
I could just wrap the if stament around the <li>
element but that would loose the purpose of what im trying to do. Is there any way i can add the <li>
elements inside the if statement ?
Function
<?php if(class_exists('MultiPostThumbnails')
&& MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) {
MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL, 'post-secondary-image-thumbnail');
}else {
} ?>
result
<img src="..."/>
desired result
<li> <img src="..."/></li>
The source code is
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => 'post'
) )
;new MultiPostThumbnails(array(
'label' => 'third Image',
'id' => 'third-image',
'post_type' => 'post'
) );
}
Instead wrapping <li>
around if statement, you can use get_the_post_thumbnail()
instead of the_post_thumbnail()
. The function will return you the img tag as string but will not echo it.
You can do string manipulation/add tags and echo it whenever you want.