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

Forcing a file to download using php headers

Date: 4th May 2009 at 11:57 am | Filed under: development, scripts | Author: Sam Burdge | Tags: , , ,

If you create a hyperlink to a media file that can be opened within the browser such as an mp3, mpg, jpg, pdf, etc. a single left click will open the file in the web browser instead of triggering a download. To download the file you need to right click (CTRL + click for mac) and choose 'Save File As...' from the dropdown.

If your intention is to create a link for the user to download the file rather than viewing it in their browser you can do so using a simple php script. Create a file called 'download.php' and copy in the following php:

<?php
$download_file = $_GET['file'];
$download_file_name = $_GET['name'];
$handle = fopen($download_file, "r");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$download_file_name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($download_file));
ob_clean();
flush();
readfile($download_file);
fclose($handle);
exit;
?>

You can then create your download links like so:

www.example.com/download.php?file=images/example.jpg&name=hello.jpg

The URL should include the path to the file to be downloaded, and the name you want to give the file. In the above example the file is 'images/example.jpg' but the name of the file downloaded by the user would be 'hello.jpg'

When using PHP headers it is important to note that the headers will only be executed if they are called before any text is output to the page. Any html, or php echo tags, before the headers will cause the headers to be ignored. A line break or space before the opening php tag will also prevent headers from working.

Leave a Comment

little bits of mischief website

Date: 23rd April 2009 at 2:25 pm | Filed under: portfolio | Author: Sam Burdge | Tags: , , , , , ,

lbom-screen2

A simple 5 page site built for music composition, sound design and music searches company 'little bits of mischief'. The site is built in php / XHTML and features Flash audio and video players. It's always a pleasure for me to build simple, classic designed sites. I particularly like the red, white, blue colour scheme in this design.

Check it out: www.littlebitsofmischief.com

2 Responses to “little bits of mischief website”

  • Comment by Lynette
    Date: June 13th, 2009 at 1:26 pm

    Please how do I just rotate a simple circle in flash on mouse over and stop on mouse away.

  • Comment by Sam Burdge
    Date: June 14th, 2009 at 4:42 pm

    Hi Lynette
    I don’t see how this question relates to this article, but:
    1. Draw a circle
    2. Convert your circle to a button
    3. Create a keyframe on the over state of the button
    4.select the circle in the over keyframe and covert it to a movie clip.
    5. edit the movie clip to include a motion tween
    6. on the first frame of the motion tween edit the frames properties - setting rotation to either clock-wise or counter clock-wise

Leave a Comment

Video Gallery - Neil Stewart / Fella Pictures

Date: 21st April 2009 at 3:41 pm | Filed under: development, portfolio | Author: Sam Burdge | Tags: , , ,

This week I have been working on improving the 'Moving Image' section of photoneil.com. When I first built the site (designed and built by 76 Creative) the Moving Image page featured Neil's video showreel, since then video has become a more prominent aspect of his work so I have created a video gallery page for the site, allowing him to showcase a range of his video work under different categories.

As this video gallery uses seperate pages for the video list and the player itself I programmed it in PHP using the Longtail / JW Player to play the flv videos. For more information about encoding video for Flash as flv see my article: Encoding FLV

The video gallery also offers the option to download higher quality Quicktime Movies of each video. I encoded the quicktimes using the mpeg-4 codec and reducing the frame size slightly to allow for higher picture and sound quality while keeping the filesizes reasonable for a download.

Check it out: www.photoneil.com/movingimage.php

Leave a Comment

Admin76 Web Content Management System

Date: 22nd January 2009 at 9:43 pm | Filed under: development | Author: Sam Burdge | Tags: , , ,

Admin76 is a powerful and versatile web content management system (CMS) designed and developed by 76 Creative. It is a PHP / mySQL driven project, for which I developed it's coding framework.

The main difference between Admin76 and other commercial CMS's is it's potential to be tailored exactly to the website it is powering. It can be transformed into a very 'bespoke' system, and so can be used to power many different genres of website, from a simple 5 page website, to a large news site, image or video gallery or a recruitment site. The only controls available in the CMS will be the exact controls you need to manage your site, nothing more, nothing less!

Other CMS's have certain 'tendencies' which relate to their intended user-base. For instance, WordPress is very much associated with blogging, Drupal is associated with community-driven sites. This is reflected in the possible themes, plugins and addons available for each.

Admin76 on the other hand is more flexible in this respect.  It can power a site with static pages, and news with categories and date based archives in the same way that WordPress can, but it can also power all sorts of different types of lists, with as many custom fields as you wish, e.g. address lists, list of file downloads, event diary, mp3 playlists, video playlists, etc. It can even be made to output XML, so it can be used to fully manage Flash Sites too.

As Admin76 is currently only available to customers of 76 Creative it has no 3rd party features, like plugins etc., available. This, however, is another strength of the system. All of Admin76's features are built in. It has an advanced image gallery system, with multiple file upload, medium size and thumbnail image creation.

Other standard features include RSS Feeds, Multiple Authors / Administrators, Flash Slideshow System, Flash Video Gallery System.

For more info about Admin76, and to enquire about getting your own self-managed, elegantly designed website get in touch with 76 Creative.

Some of the mySQL and PHP functions I have utilised in Admin76 will soon be available as tutorials on my site.

1 Response to “Admin76 Web Content Management System”

  • Comment by New e-commerce module for Admin76 CMS | Sam Burdge
    Date: June 26th, 2009 at 12:16 am

    [...] cart76, e-commerce I have been working for some months now to develop an e-commerce module for Admin76,  the CMS which is currently exclusive to 76 Creative. The e-commerce module, called Cart76, [...]

Leave a Comment