Author Archives: Patrick McGoohan

Get the Category ID by the Category Name

Here’s a handy function that takes the category name and returns the category id: function get_category_id($name) {     $term = get_term_by(‘name’, $name, ‘category’);     return $term->term_id; } Save this function to functions.php and call it like any other function. In this example we use it to return a list of all posts in a category […]

Reading and writing to association tables in CakePHP

When two models have a HABTM relationship (resisting the urge to make a joke) there is necessarily a shared association table. But what if we want to store more information in that table? While, for example, an association table between Events and Waiters (with Events HABTM Waiters) would be very useful, it would be even […]

Finding the Base URL in CakePHP

If you need the base url in a view, use this: <?php echo $this->webroot; ?> If you need the base url in a controller, use this: Router::url(‘/’, true);

Using “OR” conditions in CakePHP

Qualifying a query in CakePHP is as simple as adding conditions to the conveniently-named “conditions” array, like so: // return array of all musicians $all = $this->Musician->find(‘all’); // return array of all available reed players $only_available_reeds = $this->Musician->find(‘all’, array( ‘conditions’ => array( ‘category’ => ‘reeds’, ‘status’ => ‘available’ ) )); If the array contains multiple […]

Finding the current theme directory in WordPress

WordPress is, for the most part, pretty intuitive. However, one place where WordPress complicates things unnecessarily is in finding the current theme directory. That’s not to say there aren’t intuitive ways of obtaining this information already built into WordPress: Need the current theme URL? Use get_template_directory_uri(). Need the absolute path to the current theme directory? […]

Animated scrolling with jQuery

It’s simple enough to use anchor tags to permit a user to move from one part of a page to another. Well, perhaps not “move” as much as “jump jarringly”. Isn’t there some way of doing the same thing with a little more panache? Of course there is. jQuery has two functions, offset and animate, […]

WWW is dead. Long live WWW!

The discussion over whether one’s domain needs a “www” prefix is lively and on-going. Some are staunchly against; others are stubbornly in favor. (And no one can seem to resist borrowing from Hamlet.) Seeing I’m never as interested in what’s right as much as what works I present both methods and allow the reader to […]

Redirecting to a subdomain

It’s a familiar scenario. The client is looking to establish a web presence as quickly as possible, usually in the form of a blog, usually WordPress, which is usually installed in its own directory which is usually named “blog”. While the main site is coming together we want people to see the blog when they […]

Excluding directories from version control

The relief and joy I feel after placing a project under version control is usually tempered by the frustration that almost immediately, almost invariably follows the first time I run svn status and see system-generated files in the tmp or cache directories turning up. [I had this happen recently with a site I was building […]

Placing a project under local version control

Before I start work for a client I always push to set up some sort of versioning (usually Subversion), regardless of whether there’s going to be a team doing the development or just me. I store the repository on a separate server, just to give the project the best chance at recovery should something untoward […]