Web Development

Articles on PHP and web development tools and frameworks. We include CMS-driven development using WordPress and Joomla!

Responsive Font Size with CSS

Making your font-size respond to viewport or container size should be a must to complete your responsive designs. Having a fixed font-size accross devices is not always a good idea. The key point is to get a readable font size and a comfortable line length in most viewports. CSS viewport units and media queries provide the means to implement a responsive font size.

Continue reading

WordPress Related Posts in 4 Easy Steps

Adding Related Posts to WordPress is a great way of keeping your users reading your site for a little longer. There are two ways to add a WordPress Related Posts section: installing a plugin or doing it yourself. I would use plugins for a lot of things but adding related posts is so easy that using a plugin feels like overkill. If you know how to tweak WordPress, doing it yourself will give you more control over the displayed posts and layout.

Continue reading

K2 Joomla extension tutorial

The K2 Joomla extension was built as a complete replacement for Joomla's default article system. K2 adds important features that Joomla misses like comments, image auto-resizing and author profile pages. It gives Joomla a level-up as a blogging platform, adding the features that make WordPress great. Joomla has the plus of having tons of settings which allow to personalize the exact behaviour of pretty much everything.

Continue reading

Responsive Ads with Google AdSense

Responsive websites using CSS3 media queries are getting more popular every day. The convenience of a single design that adapts to virtually any device makes responsive design a very practical approach. In responsive design, images are usually scaled by using percentage widths in CSS. However, AdSense ads won't work the same way.

Probably a second impulse when implementing responsive ads is using display:none to hide wide ads in small viewports. However, using display:none on AdSense ads is explicitly prohibited by Google in their Ad Implementation Policies. There are just three alternatives for responsive websites:

Continue reading

Creating and Extending CodeIgniter Helpers

CodeIgniter helpers are groups of utility functions you may need anywhere in your code. CodeIgniter has more than 20 helpers. You may be familiar with the URL, email, form or file helpers. These have functions that simplify common tasks when working with URLs, emails and files.

Whenever you feel the need to add a function to a view (which is not a good practice) it may be time to extend a CodeIgniter helper or create your own helper. For example, formatting dates directly in the view can get tedious and you may be repeating lots of code. This is specially true if you need to show time in some special, non trivial way, like showing time elapsed. In this case extending or creating a helper might be the best choice.

Continue reading

Fix PHP strftime %e on Windows

If you are being bugged by PHP's strftime returning false (printing nothing) when using %e modifier for day of the month on Windows then you are in the right place. It's easy to skip the huge warning red box at the bottom of strftime function page:

Warning: The %e modifier is not supported in the Windows implementation of this function. To achieve this value, the %#d modifier can be used instead.

The solution is simple: if you are using Windows only and will never move to a Linux server (which is unlikely) just change %d for %#e. If you want to make your code work on either system, it's easy to detect the OS using PHP_OS and use the correct modifier. For example, to make $format = '%B %e, %Y' (which gives "August 4, 2013") work on both Windows and Linux you can use:

$format = '%B '.((strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? '%#d' : '%e').', %Y';
$formated_date = strftime($format, $unix_timestamp);

This code checks for the OS and uses %e just if it's running on a Windows server.

If you are using %e for several formats it may be easier to create a function to "fix" strftime. Here is the function taken from php.net:

function fixed_strftime($format, $unix_timestamp) {
    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);
    }
    return strftime($format, $unix_timestamp);
}