0

How would I place the following:

<?php if (function_exists('premium_slider')){ premium_slider(1); }; ?>

Within the echo of this:

<?php if(is_page(2)){ echo ''; } ?>

Obviously I can't do this:

<?php if(is_page(2)){ echo '<?php if (function_exists('premium_slider')){ premium_slider(1); }; ?>'; } ?>

3 Answers 3

4
<?php 
   if (is_page(2) && function_exists('premium_slider')){ echo premium_slider(1); }; 
?>

With else:

 if (is_page(2) && function_exists('premium_slider')) {
      echo premium_slider(1);
  } else {
      echo "SO Rocks!";
  }

Alternatively:

echo is_page(2) && function_exists('premium_slider') ? premium_slider(1) : 'SO Rocks!';
Sign up to request clarification or add additional context in comments.

3 Comments

If i wanted to add and else to that how would I add it?
@Guy: if (condition) { statement1; } else { statement2;}
+1 but I would split the check into two If statements instead of checking two conditions at the same time... IOW, check if we're on page 2 first, then check if the function exists, or vice versa.
1
<?php

if (is_page(2) && function_exists('premium_slider')) {
    echo premium_slider(1);
}

?>

2 Comments

This is what I now have, still having issues: <?php if (is_page(2) && function_exists('premium_slider')) { echo premium_slider(1); else premium_slider(2); } ?>
See JRL's comment above, your if() has syntax errrors. The general format is if (conditions) { truecase } else { falsecase }. you're missing the bracketing around else.
0

You can use this code exactly:

<?php
    if (is_page(2) && function_exists ( 'premium_slider' )) { 
        echo premium_slider ( 1 );
    } else premium_slider ( 2 ); 
?>

You are using closing } at wrong place.

Comments

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.