Categories
WordPress

WordPress Themes Uncluttered

For all its many merits, WordPress is weighed down by themes that are bloated and overdone, like 20th century web pages with tiresome animated graphics and far too many fonts.

Here is a list of themes that get it, letting the content take centre stage.  This list will grow over time.

Categories
PHP

Converting row attributes to variables

When you read a row from your dataset and want to work with it, like building table rows, it can be hard to write, debug and maintain your code using the conventional syntax that requires you to move in and out of a quoted string, inserting elements from the row array like this;

while ($row = mysql_fetch_assoc($result)) {
// work with the data from your row
echo "<tr><td>".row['name']."</td><td>".row['address']."</td></tr>";
}

It's a lot easier to do this if you convert your row elements to simple variables which can be placed directly in the quoted string, like this;

[sourcecode language="php"]
while ($row = mysql_fetch_assoc($result)) {
// create a variable for each attribute
foreach($row as $var => $value){
$$var = $value;
}

// now work with the data from your row
echo "

$name $address

";
}
[/sourcecode]

Your variables are created with the name of the table attribute, thus $row['address'] becomes $address.

The benefits of this second approach would far outweigh the processing cost of converting the row to simple variables unless you're working with a very high volume site where processor cycles are a significant issue.  In that case, this simplified method would serve you well during the development phase, switching to row elements just before final testing.

Categories
PHP

Setting a time zone offset in PHP

If your server is in a different time zone than your operations or your user-base, you're going to face some confusion when you use time formats to display things like time last updated, or post times.

The way to resolve this is to use the putenv() function.

[sourcecode language='php']
putenv("TZ=US/Eastern");
[/sourcecode]

To see this in action, run the following bit of code on one of your pages:

[sourcecode language='php']
echo "Original Time: ". date("h:i:s")."\n";
putenv("TZ=US/Eastern");
echo "Adjusted Time: ". date("h:i:s")."\n";
[/sourcecode]

I found a good listing of the time zones at http://www.theprojects.org/dev/zone.txt.

This is a good thing to put in the include that provides the opening page structure for your site.

Categories
WordPress

Understanding WordPress Themes

If you want to get into WordPress, and want to tweak the themes a little, you'll need do understand a little bit about how themes work.  These resources will help.

Categories
Database MySQL PHP

Time Stamp differences in MySQL and PHP

MySQL and PHP handle time and data data in different ways, and it's important to be aware of the difference.

Both these environments have a TIMESTAMP construct, but they're not entirely compatible.

While PHP uses a UNIX timestamp format (an integer representing the number of seconds since January 1st, 1970) MySQL's TIMESTAMP data type uses a YYYY-MM-DD HH:MM:SS format.

You can overcome this by using the mysql funtion UNIX_TIMESTAMP() to pull dates in the UNIX format native to PHP.

Making this conversion in your SQL query is generally more efficient and simple than converting in PHP.  Remember, you always want to work your data as much as you can in the SQL query and deliver a clean set of data to PHP.

In fact, if you like you can pull the same attribute in different ways in the same query, creating what I'll call pseudo-attributes, as in;

[SOURCECODE language='sql']SELECT UNIX_TIMESTAMP(date_attribute) AS unix_date,date_attribute AS nice_date FROM mytable;[/SOURCECODE]

This gives you two dates to work with in PHP, represented as unix_date and nice_date for a more human readable format, and balances the processing between your web and database servers.