WordPress Attachment Page Template Code Snippets

Date: 15th November 2009 at 4:25 am | Filed under: scripts, wordpress | Author: Sam Burdge | Tags: , , , , ,

I haven't written as many WordPress tutorials as usual lately, as I have been so busy building websites and blogs, so I thought I would take the time out to share a few WordPress codes I have developed recently for attachment page templates and specifically the image attachment page template. The attachment page template is the page that displays a single image when the images link URL is set to 'Post URL'. You can set the image's link URL when inserting a single image into a post, and also when using the gallery shortcode.

The codes in this article are mostly applicable to images inserted using the gallery shortcode as they are most useful for posts or pages that have multiple image attachments. Read more about using image and file attachments.

These template codes can be added to your WordPress theme using the attachment.php and image.php files. If these template files do not exist in your theme you can create them, or WordPress will default to using single.php or index.php to show attachments by default. (See more about template hierarchy).

If you don't want to create a seperate image.php or attachment.php template you can always edit the index.php or single.php files and wrap the attachment specific codes in the is_attachment clause like so:

if(is_attachment()){
//attachment page specific code goes here
}

These php functions are loosely based on code I found in this article: Adding text links to WordPress Gallery by Michael Fields. In this article he provides code examples of how to show previous and next thumbnail links in a WP attachment page. I also made use of this previous-next keys in array function which is infinitely useful!

My first set of functions will return text links for previous image, next image and back to gallery. The functions themselves will need to be added to your theme's functions.php file before calling them in your image.php or attachment.php files. So here we go:
Read on…

Leave a Comment

Basic HTML Template (XHTML 1.0 Transitional)

Date: 18th January 2009 at 11:44 pm | Filed under: scripts | Author: Sam Burdge | Tags: ,

When starting a fresh HTML site it is very useful to have a basic HTML template to use. This template should include:

  • Doctype declaration
  • Head and body tags
  • Title tags
  • Most commonly used meta tags
  • Include for a CSS style-sheet

Having an empty template document will save you time, and will ensure that you don't forget to include any of the most important features of the html page structure. This template should serve as a 'blank canvas' as it were, rather than starting with a completely blank document every time. Here is an example of my template for XHTML 1.0, which can also be downloaded from the link at the bottom of this article:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<title>HTML Template</title>
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<style type="text/css">
@import url(style.css );
</style>
 
</head>
 
<body>
 
</body>
</html>

DOCTYPE:

The doctype declaration (DTD) is important as it tells the browser what type of HTML you are using, and therefore which conventions you will need to follow when coding the site's content. For more information on this check out this Recommended  list of DTDs to use in your Web document.

TITLE:

This is the title that appears at the top of the browser window, it is also the title that appears in the google listing for your page. It is good practice to have a different title for each page of your site. The title can be split into two parts:

  1. The name of your site
  2. A description of the page

resulting in something like:  UK Diving - The worlds largest internet resource for divers (Site name - Site description) or:  UK Diving - Contact Us (Site name - Page description).

STYLE-SHEET:

The stylesheet provides all the colour, layout and text-formatting styles for your html page, it is written in CSS (Cascading Style Sheet).  Please refer to this document on Cascading Style Sheets for more info about CSS. The style-sheet can actually be written entirely between the two style tags, but I prefer to include it as a separate document, as this can be easily included in every page of the site, and once it is stored in the users cache it will also save on page loading time. The style-sheet in my example template is called 'style.css'.

META TAGS:

I use three basic meta tags in my HTML template:

  1. Content type — This tells the browser which character set you are using. In my template I use UTF-8.
  2. Description — This is the description of your page that appears in search engine listings.
  3. Keywords — A list of key words and phrases that relate to your page,  seperated by commas. This is for search engine purposes too.

ABOUT WRITING XHTML 1.0:

Here are some of the rules of XHTML 1.0.

All nested tags must be closed in the reverse order in which they are opened:

<div><span>Hello</span></div> = Correct
<div><span>Hello</div></span> = Incorrect

All tags that don't have a closing tag must be treated as self-closing with a backslash:

<img src="test.jpg" /> = Correct
<img src="test.jpg"> = Incorrect
<br /> = Correct
<br> = Incorrect

All special characters must be encoded correctly:

& = incorrect
&amp; = correct

Please feel free to use my template as a basis for your HTML pages. You can also test your HTML markup for errors using the online W3 markup validator, or the Web Developer Toolbar for Firefox.

DOWNLOAD TEMPLATE:


1 Response to “Basic HTML Template (XHTML 1.0 Transitional)”

  • Comment by pressitfor.me
    Date: January 22nd, 2009 at 6:10 pm

    Basic HTML Template (XHTML 1.0 Transitional) | Sam Burdge…

    Having an empty template document will save you time, and will ensure that you don’t forget to include any of the most important features of the html page structure. This template should serve as a ‘blank canvas’ as it were, rather than starting wit…

Leave a Comment