<?php
if ( get_option('to_breadcrumbs') == 'Yes' );
if ( get_option('to_breadcrumbs') != 'No' ) {
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
} ?>
I'm pretty new to php. Is there anything about t开发者_如何学编程he code above that should be fixed?
I think the syntax is correct, but the logic is not right. get_option('to_breadcrumbs') != 'No'
means the same as get_option('to_breadcrumbs') == 'Yes'
, assuming the value can be either yes or no.
It is syntactically correct.
if ( get_option('to_breadcrumbs') == 'Yes' );
That is not needed. There is no code being ran from outside of it.
if ( get_option('to_breadcrumbs') != 'No' ) {
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
}
This will run and do something. You can shorten it to a simple statement.
if (get_option('to_breadcrumbs') != 'No' and function_exists('dimox_breadcrumbs'))
dimox_breadcrumbs();
It is your choice to code it however you wish but the line above is preferred by most PHP programmers.
The second line
if ( get_option('to_breadcrumbs') == 'Yes' );
doesn't make sense, it doesn't do anything except call get_option()
- but the condition isn't acted upon.
The rest seems sane (not knowing what the functions actually do of course.)
I would have written it like this:
<?ph
//I'm assuming here that only you only want to run it if the to_breadcrumbs option is equal to yes.
if(get_option('to_breadcrumbs') == 'Yes' AND function_exists('dimox_breadcrumbs')){
dimox_breadcrumbs();
}
?>
精彩评论