WordPress - the Loop

Sitting bang in the middle of index.php, this is the heart of Wordpress’ functions - to print out the posts of a page.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Post Data

<?php endwhile; else: ?>

“No posts found”

<?php endif; ?>

This will display all the posts for a given page - for example, if the index page, the 10 (say) most recent posts, or if an archive page, the posts for that particular month (say). A call has gone to the database to return a given number of selected posts, in a given order.

And the second part - if no posts are available to be selected for that page, it supplies some message to indicate this…

Post content

Post content is output using the template tags. The full and rather daunting list is here.

It is possible to use other ways, but for now, why not use all the functions the wordpress developers have supplied.

Because what they output varies according to the current post [the the_post() bit ] template tags are only ever going to work in the Loop.

For example, <?php the_title(); ?> outputs the post title, as simple as that.

Similarly, the_content(), the_permalink(), etc., fairly self-explanatory.

So a very simple template for a post would be

<div class=”post”>
<h2><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h2>

<?php the_content(); ?>

<p>Posted by <?php the_author(); ?> - <?php the_date(); ?></p>

</div>

Note div class=”post ” and not div id=”post” which won’t be valid XHTML, because most likely there will be several of them on a page.

There are more complications with template tags - to be discussed…

WordPress theme - Upstart Blogger Minim

This has an excellent look to it - not too much “design” to get in the way of the content, in contrast to a lot of stuff doing the rounds at the moment - (ornament has to have a purpose, as we used to be taught…) A screen shot, but no demo yet, apparently.

“This WordPress theme is compatible with WordPress 2.1 and is designed to be:

  1. Minimalist: Very clean and easy to read.
  2. Fast: Lightweight, for speed.
  3. Ad-friendly: The columns are sized specifically to accept standard ad formats. See the README file for examples.
  4. Easy to install: You can install without plugins, though three simple plugins are recommended and included.”

Category or Tag - What’s the difference?

xml.gifThe question of category versus tag has recently been raised here - with particular reference to the fact that Technorati treats a category as if a tag - a good pragmatic real-life solution that saves all that previous messing about with links rel=”tag” - and whether the distinction should be sharpened.

So what should be a difference between ‘category’ and ‘tag’? If it were a perfect world, with perfect semantics… It’s fairly simple…

A category is an element in a hierarchy - with parents and children. This is the old way, the Open directory method, they know their place, the feudal method maybe.

In contrast, tags are designed to be mixed and matched on an equal basis, search for blog+wordpress+anything and get new and exciting joins. Tags are democracy, social collaboration, del.icio.us, and dare I say, socialism. In posh language, tags create a flat taxonomy.

Boring XML bit

And if and when XHTML 2 arrives, with its proposed navigational lists, (the nl element), it’s foreseeable that one solution might be that the list element label would equal the present usage of ‘category’ and any associated meta would be the ‘tags’.

<nl>
<label>Category</label>

<li href=”http://www.myblog.com/permalink/”>

<meta property=”tags or even dc:tags??”>

comma, separated, tags,

</meta>

Mypost title

</li>

</nl>

And then, presumably, another document to give rules for categories….

It’ll be a whole new semantic ball game when meta can go in the body of an XHTML page - and doesn’t apply to the whole document… even WordPress will be affected.

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…

Sponsored WordPress Themes - What Problem?

So, how many designers of themes embark on their fine work entirely altruistically? Not many. I did a couple of themes a couple of years ago, leaving them on my web development site, and they still contribute significantly to the PR of the front page. This allows the sale of text links and is a nice little earner month by month. Theme designers do it for the exposure, direct or indirect, the vanity, ultimately the cash, (as well as that warm feeling inside of having put something back).

So it’s a issue that’s always been with us - the discussion is of sponsored themes and the practice of pre-placing links, static/dynamic, visible/invisible to humans in return for hard cash.

The “where does one draw the line” arguments.

Text Link Ads have a whole business built on a parallel practice, to little public alarm, perhaps an example of the inevitable “if you’ve got a well-designed web presence it all looks better”. I note they have just introduced sponsored links for some individual posts.

Is the assumption that sponsored themes lead to an increase in the rubbish out there, strictly accurate? - the quality of coding appears to be slightly higher, if anything…

It is always possible to take a free theme and strip out anything you don’t fancy… The converse, taking someone’s theme and rebranding as your own is far far worse, but attracts less discussion because there ain’t nothing to be done about it…

Weblogtoolscollection have made the decision not act as the police, or indeed magistrates, for the community - they say that they will permit sponsored themes to be promulgated on the site, but not given any priority and dropped in the case of any severe infraction. The talk is of “a nasty taste in the mouth”, presumably left by the naked capitalism of sponsorship left standing so close to the OpenSource ethic.

I would disagree slightly. If you do consider the situation is on fire, then fire has to be fought with fire. A certain large corporation, that started off as a search engine, drops sites with or without reason, and certainly without a second thought, on the “it’s my site and I’ll have who I want to” principle. Courage in your convictions, even balanced against the concept of free speech and distribution.

The guiding principle has to be protection - some are not as php-literate as others, and less well-placed to go through the code for anything nasty in the front/back door variety. There are certainly some simple exploits available, which I wouldn’t propose to describe in greater detail here. If you do come across anything you think dubious, announce it - but give the right of reply.

The future? Who knows, maybe a codecheck for wordpress themes - the successful bearing a seal of approval - but I’m not sure the situation has reached that stage yet…

More on Duplicate Content

Interesting and wise from Strange Duck Media - the issue being the duplicate content penalty again.

I would still maintain that the occasionally-quoted “WordPress is bad SEO” is an overreaction - I’ve built CMS sites that churned out 8 discrete pages for every data chunk, plus .txt and pdfs and they survived on the SERPs ok - without disappearing to supplementals.

The point about being made to feel a criminal is well-made. Large US corporations, doing evil or otherwise, are not arbiters of law, and as for how non-US citizens might feel about this…

Source-Ordered Layout code for WordPress

The days when search engine spiders only downloaded the first 20, 50, 100kB of code and Altavista was lucky to find more than 10kB, are, thankfully, gone.

The duplicate content penalty of Brin/Page and nowadays Schmidt, is the cause of much misguided paranoia but it’s worth bearing in mind that a good source-order, ie blog posts straight after the header, then sidebar(s) stuff  is the best way to rest easy at night.