Skip to content

Creating multi column layouts in WordPress

Here at Sweet-Apple we’re frequently being asked by web design agencies in and around Bath to develop web sites for them on a freelance basis. This is a good thing. We like it. We’re also keen to take their Photoshop visuals and make the website look as close to pixel perfect as time and budget permits. And one of the design features we come up against time and time again when creating WordPress themes is Category layouts that have multi columns.

When you’re making CSS layouts for multiple columns, typically you’ll do something like this:

<div class="first">Content here</div>
<div>Content here</div>
<div>Content here</div>
<div class="last">Content here</div>

So the question is how do you you append the correct class to the </div>? Inside the loop, something like this will see you forward…..

$i = 0;
$columns = 3;
//Start the_loop
$i++;
$columnPosition = "";
$mod = ($i % $columns);
switch ( $mod ){
case 1:
$columnPosition = "first";
break;
case 0:
$columnPosition = "last";
break;
default:
break;
}
//Append $columnPosition to the array of class on the post...
post_class($columnPosition)

Looking for a freelance web developer to quickly and efficiently create websites for you? Give us a call on 01380 830224 – we’d love to help…

Posted in Web Development, Wordpress | Tagged , , | Comments Off on Creating multi column layouts in WordPress

Mac OS X Server – for the ultra low price of free…

Amongst all the normal media frenzy that surrounds Apple announcing the  new “Sandy Bridge” MacBooks, something potentially much more revolutionary slipped out under the radar. No not Thunderbolt/ LightPeak! It’s the news that OS X Lion will include OS X Server straight out of the box, for free.

Having worked with OS X Server since OS X 10.3, I’ve got a reasonable understanding of why this is. Simply put, the current Server Admin tools are too confusing for your average, and even not so average Mac geek. I’ve even been asked in the past by other Mac consultants to help set up OS X Server for them remotely, just because it takes forever to understand how to get even basic requirements like cross platform file sharing configured.

Because of this, OS X Server isn’t selling in the sort of volumes that many imagined it would. When it was launched, it offered a real cross-platform alternative to Windows 2003 Server, and could massively reduce the cost of server licences for small to medium size companies. However, this was more than offset by the additional expense of having to find someone capable of configuring OS X Server to work in cross-platform environments.

My expectation is that Apple will offer a greatly simplified set of Administration tools, to encourage SME’s to switch to Macs. If they can make configuring files, web, email and calendaring services straightforward enough, it could potentially open up a massive new market amongst business users wedded to Windows. However, they really do need to focus on ease of use. I might be happy(ish) wading through a 500 pages PDF just to learn how to configure File Sharing, most people aren’t…

Need help settings up OS X Server? Call us on 01380 830224 and we’ll get things moving.

Posted in Apple | Tagged , | 1 Comment

Common security vulnerabilities in web applications

I’ve just got back from a round of client meetings, introducing myself to a number of web design agencies in Bath. During one of those meetings I was asked to take a look at a prototype site and comment on some JavaScript issues they were having. I noticed the site was running from a bespoke web application, so being a curious sort I decided to quickly see if there were any obvious vulnerabilities in the code.

The long and the short of it is that within 30 seconds I could easily find XSS (Cross Site Scripting) vulnerabilities – and I’m not claiming by any stretch to be a web security expert.

Any website that accepts user generated content really does need to make sure that it’s  validating and filtering incoming data. It’s far too easy for someone with even the most primitive knowledge of “hacking” to play merry hell with your reputation and customers. Redirecting people to other sites, stealing session cookies, deliberately breaking the site layout, and much much more can be the end result – which really doesn’t look good at all.

So next time someone’s building a web application for you, make sure they aren’t just thinking about SQL Injection vulnerabilities, they’re also thinking about XSS…

Posted in Web Development | Comments Off on Common security vulnerabilities in web applications

Deleting apps you’ve installed via the App Store in OS X

So those of you running OS X 10.6 have almost certainly looked at the App Store, probably downloaded a few things, some of which you’ll have decided are rubbish and want to delete. So I expect you’ll have looked for a way of uninstalling or deleting them from the App Store application. And you’ll have found nothing… So how do you delete an application after installing through the App Store?

It’s simple. Delete the icon from the Dock just by dragging it off the Dock. It will disappear in a puff of smoke. All done? No. Now you have to open the Hard drive/Applications folder, find the app and drag it to the Trash.

I have absolutely no idea why Apple haven’t added a delete function to the App Store. So for now, you’ll just have to hunt around a little bit, just as you would when deleting an application you’ve installed the “traditional” way…

Posted in Apple | 1 Comment

Sorting PHP arrays of objects by an object property

Much of the time when you are working on web applications, you’ll be working with arrays of data. And frequently those arrays (or Collections) will be populated with objects. And sometimes you’ll want to sort those arrays by an arbitrary property on the objects it contains. This is where the usort function comes into it’s own…

For usort to work, you need to specify a function/method to perform the comparison, and that function needs to return -1,0 or 1.


class MyClass
{
public static function MySort( $a, $b)
   {
        if($a->property == $b->property) return 0;
        if( $a->property > $b->property){
           return 1;
        }else{
           return -1;
        }
    }
}

// Using it...
$collection = MyClass::fetchAll();
usort($collection, array("MyClass", "MySort"));

Obviously you can put more interesting logic into your MySort function. If you’re sorting on dates, you’ll want to do some DateTime object comparisons, for example.

Now you’re almost certainly wondering why you don’t add the sort into the ::fetchAll method, but sometimes you don’t have easy access to modify the API, and hence need to find workarounds…

Posted in Web Development | Comments Off on Sorting PHP arrays of objects by an object property