WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] HELP... If else statement not working...! (11 posts)

  1. Janu Studio
    Member
    Posted 3 years ago #

    Hi there all i am using a photo plugin the thing is that i am trying to make my own conditional statement where i am trying to do is that

    i want to make these two statements in a conditional format by using these two statements

    IF

    <?php if ( function_exists( 'userphoto' ) ) { userphoto($posts[0]->post_author); } ?>

    ELSE

    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />

    How do i make this so i get if fucntion or if its not available i get to show my default avatar image...

    Thanks

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    What's wrong with using:

    <?php if ( function_exists( 'userphoto' ) ) :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>
  3. Janu Studio
    Member
    Posted 3 years ago #

    Thanks a millions esmi, i just didnt had the concepts of making conditional statements... but this isnt solving out the problem because the if there is not photo it shows nothing a simple white n i guess thats because we are using if plugin exist function ...

    what i need is that

    if photo exist or else
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>

    just like where you told above if function extist...

    <?php if ( function_exists( 'userphoto' ) ) :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Try:

    <?php if ( function_exists( 'userphoto' && userphoto($posts[0]->post_author != '') ) :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>
  5. Janu Studio
    Member
    Posted 3 years ago #

    Its breaking theme... :( it says error on line 32 which is the line

    Line 32
    <?php if ( function_exists( 'userphoto' && userphoto($posts[0]->post_author != '') ) :

    From your follow code the first line is breaking theme...

    <?php if ( function_exists( 'userphoto' && userphoto($posts[0]->post_author != '') ) :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>
  6. esmi
    Forum Moderator
    Posted 3 years ago #

    I can see it! Try:

    <?php if ( function_exists( 'userphoto') && userphoto($posts[0]->post_author != '') :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>
  7. Janu Studio
    Member
    Posted 3 years ago #

    Sorry esmi, :(

    Its again breaking themes the error comes at line 32 which is the first line of your code... pasted in dreamweaver to see where error occurs the first line's <?php and the else :?> are highlighted in red...

    <?php if ( function_exists( 'userphoto') && userphoto($posts[0]->post_author != '') :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>
  8. esmi
    Forum Moderator
    Posted 3 years ago #

    Sorry about this. I'll get the bracket placement right eventually...

    <?php if ( function_exists( 'userphoto') && userphoto($posts[0]->post_author) != '') :
    userphoto($posts[0]->post_author);
    else :?>
    <img src="<?php bloginfo('template_directory'); ?>/images/blank_avatar_176x132.gif" width="132" height="176" />
    <?php endif;?>

    Also bear in mind that I have no idea what userphoto($posts[0]->post_author) normally returns.

  9. Janu Studio
    Member
    Posted 3 years ago #

    AND YOU GOTTTTT ITTTTT!!!!!!!!! Esmi so much thankyou.... Thanks a tonsss..... God bless you simply... thats so cool... that u solved this big prob in munites!!! Thanks a tons... I would luv to return a favor via my blogs in future... thanks alot very much

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    Glad to hear that we got there in the end. Seems like you've been passing the favour on and trying to help others on the forums already. :-)

  11. Janu Studio
    Member
    Posted 3 years ago #

    :) Thanks i do look forward to help others and expand my knowledge and experience... just like you... :) Thanks a tons...

    You saved the Day...!!! :D

Topic Closed

This topic has been closed to new replies.

About this Topic