Posts tagged: php

PHP Calendar Functions

It’s really easy to get really mixed up when trying to program with date functions – lots to keep track of, calendars, timezones, daylight saving, weird months that have different numbers of days in them…

WP-Cron – automating and scheduling

You need a cron job in your WordPress blog – something run to a schedule, hourly, daily… Instead of fixing up a crontab and using wget or lynx, you can use WordPress’s internal version of the cron job.

Version Testing for WordPress Theme Design.

WordPress is (mainly) backwards-compatible in terms of its core code. But the code connected with themes or plugins that you add may well not be. For example, v2.9 has post thumbnails – put these in your new theme and they won’t work for older installs of WordPress – so some version testing is required.

A jQuery Slideshow for WordPress 2.9

You want a jQuery slideshow for your WordPress blog? – on the front page, or maybe in the sidebar? No real problem, all the javascript is taken of with the help of a jQuery plugin, all we have to do is figure out how to get the post data.

And to keep things really simple, this is going to use the thumbnail functions in WP 2.9 – no need to mess around with custom fields any more.

WordPress Action Hooks – the simplified version

WordPress action hooks allow you to access the functions of the core WP code, without messing around with that code. It’s the basis for most plugins (the whole business essentially started out as the plugin API), but themes are using them more and more and there’s no reason not to…

do_action/add_action are also the means of getting external scripts, CSS, javascript/jQuery correctly on the page.

WordPress – Display Random Posts

So you want to display a random list of posts, maybe in a sidebar widget… One way to do it is to use the query_posts() function, but this isn’t always the best…

WordPress Theme Frameworks

Since the arrival of WordPress 2.7, the true framework is based on the concept of parent/child WordPress themes. A child theme is dependent on its parent – here, the framework – for its template files and functions, it’s not going work without it.

Multiple WordPress Queries – Duplicates

You’ve got 2,3,4… custom post queries on a page and you need to get some control over duplicates – it looks unprofessional if your theme keeps showing the same stuff. Let’s take the example of displaying separately posts from 2 different categories – but if a post is in both categories, not duplicated across the [...]

WordPress, Twitter and URL-shortening

You’re producing a WordPress theme, or plugin, that is related to Twitter and for obvious reasons you want to include url-shortening functionality… How’s it, generally, done?
Just the briefest snippet of PHP, this example for is.gd:-

function shorten_url($url) {
$request = 'http://is.gd/api.php?longurl=' . $url;
return @file_get_contents($request);
}

WordPress Custom Category Archives

Note, we’re talking here about different category archive pages – not having a post page customised according to the category that post is in….
There’s 2 ways of doing this – first, the simple way, for more minor changes to the overall theme template, you can use the is_category function: