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…

5 Responses to “WordPress Attachment Page Template Code Snippets”

  • Comment by doriggidy
    Date: April 25th, 2010 at 8:08 pm

    Hi this is a great tutorial. I’m currently using nextgen gallery but want to try your gallery on my sister’s blog…so using the built in image features of WP seem to be the best solution. What you have here should be perfect for her. Great job. One question, If I wanted to have the images themselves link to the next image…how wold i do that?

  • Comment by muscle car
    Date: May 24th, 2010 at 4:29 pm

    hay that’s the cool one,but how to create thumbnail picture in random,place in sidebar or in home page header,thaks b4

  • Comment by Ted
    Date: May 27th, 2010 at 11:47 pm

    This worked perfectly for me … except, for some reason I can’t get the image captions to display. Any thoughts why they might not be coming in?

  • Comment by Shariff
    Date: July 7th, 2010 at 4:13 pm

    Wonderful Tutorial, at last I found it, I am going to try this in my blog.

    Great Going

  • Comment by Jason
    Date: July 9th, 2010 at 4:16 pm

    Thank you for this tutorial, it helped me immensely.

Leave a Comment

New Wiki site for Football FanCast

Date: 20th July 2009 at 5:30 pm | Filed under: development, portfolio | Author: Sam Burdge | Tags: , , ,

fanswiki-screen

I have recently been working on my first project on the MediaWiki platform, a football wiki site for FootballFanCast.com. The Football Fans Wiki is a wiki written from the fans perspective, with information about each team's stadium, transport info, where to eat & drink locally, songs, programmes, merchandise store, links,video clips & more.

Key features that I added as MediaWiki extensions:

  • Register and login from the FFC site instead of through MediaWiki itself
  • News & blog feeds on the wiki homepage

Check it out now: Fans Wiki

2 Responses to “New Wiki site for Football FanCast”

  • Comment by Andy
    Date: September 15th, 2009 at 1:09 pm

    Brilliant work mate. Was looking into doing something like this for my Scottish Football site but don’t know where to start etc.

  • Comment by fashion storm
    Date: October 23rd, 2009 at 6:33 am

    i am using your amazing wordpress layout and i love it but i was wondering how i can change the header to a custom one that i have. it doesn’t blink or anything it is just a png. file. help! please. you can mail me back at the email i gave you. thanks!

Leave a Comment

The Transfer Tavern

Date: 9th June 2009 at 2:37 pm | Filed under: portfolio | Author: Sam Burdge

untitled-1untitled-2untitled-3untitled-4

The Transfer Tavern is a pub themed blog / site about football transfer rumours. It features two different voting systems by which readers can vote on the pluasability of each rumour, deciding whether the rumour should 'Fly or Die' and also a beer rating to decide how drunk you would have to be to believe the more outlandish rumours.

The most interesting and challenging aspect of building the site was designing and implimenting the custom voting systems. I also designed the pub style logo for the site which I am quite pleased with! If you like to keep up to date with all the latest footy rumours, or want to find out what purchases your team might be making over the summer transfer window then be sure to check it out: www.footballtransfertavern.com

Leave a Comment

The Football Journalist - Blog Customisations

Date: 4th May 2009 at 1:00 pm | Filed under: portfolio | Author: Sam Burdge | Tags: , , ,

tfj-screen

The Football Journalist is a blog site aimed at people who want to become professional sports and football journalists. It features listings of sports journalism courses and jobs within the football industry.

I applied a few basic customisations to the theme, changing the background image and adding in the adsense blocks and job listings widgets. I also used a few of my favourite plugins to apply SEO to the site.

As the site is linked with FootballFanCast (one of the leading football blog and podcasting sites in the UK) I would highly recommend it for anyone who is working towards a carreer in football journalism.

Check it out: www.thefootballjournalist.com

Leave a Comment

Zakeeya.com - Art & Photography blog sketchbook

Date: 2nd April 2009 at 9:20 pm | Filed under: portfolio | Author: Sam Burdge | Tags: , , , ,

zakeeya-screen

This simple, elegant blog was designed and built by 76 Creative (coded by me:¬)  for London based artist Zakeeya. It is powered by the Gallery Mangement feature of Admin 76, 76 Creative's custom Content Management System.

The Gallery Management system was originally intended for creating a series of galleries, rather than one huge one, so although being simple in appearance on the front end, the back end of this site still posed one or two challenges for me and allowed for improvements to be made to the CMS in the process.

Another thing I enjoyed about this site is doing a layout with a fluid width in CSS, most sites I have done are fixed width so it was interesting to change things up a bit.

I'm a big fan of simplistic / minimal websites where the content is the main focus.  Check it out:

www.zakeeya.com

Leave a Comment