Category: php

Getting started with WordPress Plugins

Devlounge.net is midway through a comphrensive guide, how to write a WordPress plugin. It’s simple and sensible.I’m sure it will be mentioned there in some form or other, but what got me started and probably the best overall advice on the subject is:- download a plugin and dissect the code - oh - and if it’s not too obvious- pick something simple first…

WordPress Header Page Links - wp_list_pages

You want to list your pages as fixed links, for example in the header of the theme, rather than simply use the sidebar lists, with widgets or otherwise. In WordPress, this is handled by the wp_list_pages() function.

Read more »

WordPress Theme - Mimetastic

Interesting and unusual theme from the maker of Spiffty. The title in the metadata box takes a little getting used to, but definitely worth checking out…

Mimetastic is a blue, minimalist, single-column theme. It features a menu at the top of the page instead of a sidebar. It is a fluid-width theme intended to be easy on the eyes and provide a focus on the content of the website instead of its theme.

Available here

WordPress and XAMPP

Xampp is the best of Open source - and a good way to have a development version of WordPress. When time permits, I’ll get together a guide to installation with particular regard to WordPress. There’s a good one for Xampp Lite on a memory stick here. And also one for WAMP…

For now, life goes much better if it is installed at the root ie C:\xampp\ rather than C:\Program Files\xampp\ (that’s an absolute for Vista, but strongly suggested for XP etc) And don’t dedicate anything as a service.

First WordPress Theme: 3 - Header and Footer

Separate header and footer files - PHP includes

As a programming language, PHP was expressly designed to work in close conjunction with (X)HTML.

A major part of its usefulness are the include functions, where a separate file and its php code is “included” into a main file - (this allows files to be edited independently, or you can even select different files, and therefore different code, to be included depending on your requirements).
Read more »

First WordPress Theme: 2 - A sidebar

Adding the sidebar to the basic layout.

For simplicity, we’re just going to do 1 sidebar - adding 2,3 sidebars follows the same principles, but with a few complications best left for later.

1. Go to your index.php (from the first wordpress theme tutorial) and cut out the code for the sidebar:- probably something like this

<div id="sidebar">
....
Some dummy text at the moment
....
</div>

Read more »

Customizing WordPress posts by Author

You’ve got a multiuser blog and want mugshots of the different proud authors next to their posts - this is how…

The key is to use the template tag the_author_ID()

This returns the numeric value of the user ID for the current post - unlike the category or categories of a post, it’s unique - so the programming becomes relatively simple. See wp-admin/users.php for the values on your blog

In strict programming terms, this is a bit of bodge - or you could say it takes advantages of the unique flexibility of PHP to dip in and out of HTML code. The following block of code needs to go within the Loop of posts on index.php. We are going to switch the value of $image_path according to the value of the function the_author_ID()

<?php

switch (the_author_ID())
{

case 1:
$image_path = ‘http://www.mysite.com/uploads/john.jpg’;
break;

case 2:
$image_path = ‘http://www.mysite.com/uploads/mary.jpg’;
break;

default :
$image_path = ‘http://www.mysite.com/uploads/default.jpg’;
}

?>

Don’t forget the break;

Probably best to use absolute urls in this case, especially if you’re using mod_rewrite seo-friendly urls. And the form of the post will be something like this

<div class=”post”>

<div style=”float:right;”><img src=”<?php echo $image_path; ?>” height=”140″ width=”100″ /></div>

<h2><?php the_title(); ?></h2>

<?php the_content(); ?>

</div>

Further work
For perfection, you might want to use relative locations in the filesystem and check that the photo exists before outputting a broken path, using file_exists()

and, if not, supplying a default that you know does exist.

Also life is going to be easiest if all your photos are the same size - if you don’t want to make your life easy, something like this is the way to go:-

case (2):
$image_path = ‘http://www.mysite.com/uploads/mary.jpg’;
list($width, $height, $type, $attr) = getimagesize($image_path);

break;

But see getimagesize for details

There’s lots more to do with individual authors and their posts…

(These discussions assume some working knowledge of php and how to put it together - the code is given as suggestions, so you’ll need to do a bit more than just a cut ‘n paste to get results for your blog…)

Wordpress Theme - Tarski 1.4

Tarski (a real labour of love) 1.4 is newly released and can be obtained here. We’ve used Tarski on 3 or 4 installations and it does the business.

“Tarski now works right out-of-the-box with WordPress MU. The theme will now auto-detect WPMU and tweak its functioning accordingly; the specifics are in the changelog.”

Many years ago, in another life (Berkeley, USA), I briefly met Alfred Tarski and had to run through some Theory of Groups stuff with him - not especially his field and certainly not mine - he was forbidding, rigorous, irascible, but almost to a comedy extent…

Ultimate Tag Warrior Unbroken

Having upgraded to WordPress 2.2 on 2 other sites and been contacted by precisely 2 unhappy punters complaining about their tags going awry, some searching was in order and I came up this sensible advice on the Ultimate Tag Warrior plugin

While definitely appearing to be a nice well-thought-out chunk of code (haven’t got down to looking at it any detail) I must confess to not being a total fan in practice - just occasionally too much can be added in terms of function - is that a bit churlish? probably…