Forum Moderators: coopster

Message Too Old, No Replies

Which is the safest way of having code do nothing? example inside.

         

JS_Harris

6:07 am on Apr 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi, I have a bit of code that I'd like to run on a wordpress driven blog, on every page UNLESS they belong to a certain category, in which case I want the process to simply move along.

Here is an example, it first checks to see if the call is being made from the category (35 in this case) and if it is the code does nothing, if the article doesn't belong to category 35 it executes.

Is there a more efficient or SAFER way of doing this or is this fine?

<?php
if ( in_category( '35' )) {
// do nothing
} else { echo '<p><b>A welcome message</b>...</p>';
thefunction_torun();
}
?>

I'm concerned that the // do nothing may make a browser choke...

g1smd

10:17 am on Apr 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It can't make a browser choke as nothing is sent to the browser.

PHP is evaluated inside the server only.

In cases like this, I would be tempted to make a negative match:

If var does not equal a value, do something...