0

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'
 ) );

 }
2
  • Can you provide the source code to MultiPostThumbnails::the_post_thumbnail as that seems to be producing the output Commented Jul 31, 2013 at 9:25
  • @fullybaked Ofcourse forgot that :) its updated now. Commented Jul 31, 2013 at 9:30

1 Answer 1

1

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.

Source: http://voceconnect.github.io/multi-post-thumbnails/

Sign up to request clarification or add additional context in comments.

2 Comments

@adnanyyousafch Sorry to bother your, but i cant seem to find how to echo out the string. . any tips ?
how about echo '<li>' . MultiPostThumbnails::get_the_post_thumbnail('post', 'secondary-image', NULL, 'post-secondary-image-thumbnail'); . '</li>' :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.