WordPress Attachment Page Template Code Snippets
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…











good article, thanks for this useful info, I have dug and stumbled this article. I will keep visiting for more useful information.
great article. thank
this game is so good I have played it several days ago
Keep it up man! Now, when I need useful info I’ll come here.
Smarter than an average blog…cheers
Nice Kindly visit my site
[...] Games Arcade Website powered by WordPress Sam Burdge Posted by root 19 hours ago (http://www.samburdge.co.uk) 4 responses to games arcade website powered by wordpress comment by ashish date march 17th 2009 at 7 58 am good article thanks for this useful info Discuss | Bury | News | games arcade website powered by wordpress sam burdge [...]
This is a great game. Great info
[...] Games Arcade Website powered by WordPress Sam Burdge Posted by root 6 hours ago (http://www.samburdge.co.uk) 5 responses to games arcade website powered by wordpress comment by ashish comment by budi date april 23rd 2009 at 1 34 pm keep it up man reliable web hosting linux amp windows hosting starting at just 1 99 per month Discuss | Bury | News | games arcade website powered by wordpress sam burdge [...]
wow i think wordpress just for blog, but im wrong, good idea bro
visit mine i have lotz of free games too -yay-
Nice plugin, made myself also a mochiads wordpress plugin, its still in decelopment.
i heavily cusomized a video theme for the layout.
you might wanne check it some times.
god job…
grts,
chris
Hey, this is cool free stuff
Awesome post. Very informative
This post must contain keywords that are attracting too many spam bots. Sorry but comments are now closed on this post.
i am new to wordpress but i like this site, good article… and i like the sound od the flash arcade….
i have downloaded your beta plugins, nice plugin mate, thanks
So, this is interesting for me, I will translate it and post to my saite http://grang.info Thanks, Alex
Great article, adding it to my bookmarks!
Great work with the blog mate let me know if you want to partner up with my blog as well! =]
Nice your beta
I’ll gonna translate in romanian language this post and i will put a direct link to your site. Thank you
Very cool. I finally got around to changing my own games site, http://www.kwikgames.com over to Wordpress earlier this year. After years of updating static HTML pages it was high time I made the switch and was thoroughly worth it…
I love your thumbnail “grid”! You might want to use a rating plugin, there are quite a few good ones, so you can show most popular games and encourage more user interaction, but overall it looks great. And to anyone thinking of using WP for a games site I highly recommend it!
that is what i need
thanks!