tracedef Posted January 13, 2010 Share Posted January 13, 2010 We have a wordpress plugin that enables users to plugin in values in the wordpress dashboard that are then populated in our theme template using the following tag <?php if( function_exists('lp_tag') ) { echo lp_tag('phone'); } else {}?> . In this example it will echo the phone number, other tags are 'address', 'hours', etc. This enables us to hard code the plugin call into the template but enable users to control the values without having to touch any code via the dashboard. One of the tags is 'id_number". Our goal is to check to see if "id_number" has a value that is is greater then 0. Our goal is to put together the PHP conditional statement that does the following: if 'id_number >' 0 then do "various code" else do "various code". Something along the lines of the following, but obviously with some corrections as we're definitely a bit off with what we have come up with: ?php if ( lp_tags('id_number') > 0 ); ?> <link rel="stylesheet" type="text/css" media="screen" href="style1.css" /> <?php else ?> <link rel="stylesheet" type="text/css" href="style2.css" /> <?php endif; ?> Any feedback on the correct way to write this statement is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/ Share on other sites More sharing options...
Sesquipedalian Posted January 13, 2010 Share Posted January 13, 2010 You were close; I corrected your code: <?php if ( lp_tags('id_number') > 0 ): ?> <link rel="stylesheet" type="text/css" media="screen" href="style1.css" /> <?php else: ?> <link rel="stylesheet" type="text/css" href="style2.css" /> <?php endif; ?> You placed a semicolin instead of a colin after the first if, and you needed a colin after the else also. Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994007 Share on other sites More sharing options...
oni-kun Posted January 13, 2010 Share Posted January 13, 2010 if ( lp_tags('id_number') > 0 ) { echo '<link rel="stylesheet" type="text/css" media="screen" href="style1.css" />'; } else { echo '<link rel="stylesheet" type="text/css" href="style2.css" />'; } It's more preferable to use conditional blocks, As you'd be able to spot obvious errors easier and it is more clean.Your ELSE statement was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994009 Share on other sites More sharing options...
tracedef Posted January 13, 2010 Author Share Posted January 13, 2010 I really appreciate everyone's help, thank you for helping me get this straightened out, you made my night! Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994013 Share on other sites More sharing options...
tracedef Posted January 13, 2010 Author Share Posted January 13, 2010 If I want to insert a PHP call in the "else" part of the statement the following works, but it probably isn't the best or pretiest way to accomplish this, any feedback on a more correct way to insert a php call in the else statement? <?php if ( lp_tag('loansifter_id') > 0 ) { echo 'YES'; } else { if (function_exists('insert_cform')) { insert_cform('3'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994024 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 <?php if (lp_tag('loansifter_id')) { echo 'YES'; } else if (function_exists('insert_cform')) { insert_cform(3); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994028 Share on other sites More sharing options...
tracedef Posted January 13, 2010 Author Share Posted January 13, 2010 Thank you Thorpe! Finally, if I wanted to insert div's, would the following be ok in terms of best practices by simply placing it within the echo call? It works, but not sure if it is proper... thank you again for all the help! <?php if (lp_tag('loansifter_id')) { echo '<div>random text and html formatting</div>'; } else if (function_exists('insert_cform')) { insert_cform(3); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994031 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 Yeah, that is how I would do it. Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994032 Share on other sites More sharing options...
tracedef Posted January 13, 2010 Author Share Posted January 13, 2010 Thank you, have a great night! Quote Link to comment https://forums.phpfreaks.com/topic/188287-php-conditional-statement-to-check-value-of-plugin/#findComment-994033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.