WP plugin: Next-Previous Post IMG

posted on January 18, 2005

I’ve put together some WordPress plugins over the past few months, but haven’t posted anything on them (most were just described and linked on the WordPress wiki or my personal projects page). But the silence has ended. The one I’m on about here is a work in progress: Next-Previous Post IM(a)G(e), a small (ok, not all that small) redo of the WordPress next and previous post template tags, to allow images as links.

You can see Next-Previous Post IMG in operation here on guff—just look above search at the upper right of the page for the pretty link images. (Update: Switched to different mod of next/previous_post; ignore this note.)

To install, go through the regular rigamarole: download zip file, extract next-previous-img.php, upload to your WordPress plugin directory (wp-content/plugins), and activate the plugin. The tags to use are similar to the next_post() and previous_post() ones in WordPress, but have obvious differences:

Usage

<?php next_post_img('next_img', 'nonext_img', width, height, 'next', 'format', title); ?>

<?php previous_post_img('previous_img', 'noprevious_img', width, height, 'previous', 'format', title); ?>

Parameters

next_img / previous_img
(string) Path to graphic to display for next/previous post link. No default – should be set.
nonext_img / noprevious_img
(string) Path to graphic to display when no next/previous post link exists. Defaults to next_img / previous_img value/graphic.
width
(integer) Width (in pixels) for image as displayed. Defaults to true image width.
height
(integer) Height (in pixels) for image as displayed. Defaults to true image height.
next / previous
(string) Text to insert in image title/alt attributes. Defaults to 'Next post: ' / 'Previous post: '. This is prepended to title.
format
(string) Format string for link. '%' in string is replaced with the link/image, so 'Go to %' will generate “Go to <a href=…<img src=…” Defaults to '%' – No idea who’d want to change it, but it’s here.
title
(boolean) Use the title of next/previous post in title/alt attributes (TRUE) or do not (FALSE). Defaults to TRUE.

Examples

(Examples use next_post_img(); I figure you’re smart enough to extrapolate for use with next_previous_img().)

This shows a very basic implementation, with values (paths to your images) set for next_img and nonext_img.

<?php next_post_img('/images/next.gif', '/images/next.gif' ); ?>

This has values (paths to your images) set for next_img and nonext_img, as well as forcing values (in pixels) for width (20) and height (12), and changes initial image’s title/alt attribute text to “next: “.

<?php next_post_img('/images/next.gif', '/images/next.gif', 20, 12, 'next: '); ?>

Author: Kaf Oseo
Categories: WordPress
Comments: (20) · Leave a comment · Comments RSS2

BB
Comment » January 24, 2005 @ 1:59 am

I don’t understand the usage of this plugin. Will it allow users to navigate individual images, like images in a post, as I have here:

http://www.bbiverson.com/2004/01/28/trip-to-hualien/

Kaf
Comment » January 24, 2005 @ 4:48 am

Only if they’re on individual posts/pages. The point of this plugin is to provide a replacement to the two built-in WordPress template tag functions:

These provide text links to the next or previous post when navigating individual posts on a weblog. Next-Previous Post IMG lets you use images for those links.

If you scroll up to the top of this page, the two small yellowish arrow graphics, just above search, demonstrate the use of this plugin. [Edit from the future: Layouts change...]

MsCantBWrong
Comment » January 26, 2005 @ 11:25 pm

Oooo… I like how you’ve implemented the plug-in. I didn’t even think about using it in that context. Niiiice!

Right now I’m having a small problem implementing this plug-in, but I’ve sent an e-mail to Podz and hopefully he can help me clear it up.

Once I get it all working properly, I am going to post this to the Pictorialis forums and I am sure that you will have a lot of very happy WordPress photobloggers out there.

Once again… many thanks. This was a big deal to me.

Kaf
Comment » January 27, 2005 @ 10:45 pm

I’m all for happy bloggers. That they’re WordPress bloggers—and photobloggers to boot—is just a side benefit. Have fun with the plugin.

Jason
Comment » May 30, 2005 @ 11:24 pm

I’ve dropped it in my wordpress site ‘single.php’ code and it works. However, when I added it to the ‘archive.php’ page, nothing appears. Any ideas?

Kaf
Comment » June 1, 2005 @ 10:23 am

@Jason, The plugin works like next_post/previous_post in that it provides links only for single post navigation. For what you’re looking for you’d need something that replaces posts_nav_link.

aaaaa
Comment » June 4, 2005 @ 10:48 am

nice plug-in, however it doesn’t seem to be working correctly for me. i call my nav bar with an include if that makes any difference, and i’ve made sure that it’s after the wp loop. the problem being that it doesn’t link. the image shows up, but without the link. thoughts?

Joe
Comment » June 13, 2005 @ 11:25 pm

Kaf — great plugin, will be setting it up soon.. As Jason asked above, is there any plugin that exists to use images in the posts_nav_link function? Been searching all over… And way to hack yours to somehow use it for general next/previous site navigation?

Thanks!

Joe
Comment » June 13, 2005 @ 11:47 pm

ahhhh disregard…… looks like all ya gotta do is plug in inside the call to post_nav_link :)

sproke
Comment » April 15, 2006 @ 6:50 am

Went to look at urban image. it doesn’t help at all – well not that I could see, but then, I could be blind!!

sproke
Comment » April 15, 2006 @ 7:04 am

Can you please explain the useage of your plugin clearer? I want to have something similar to what you’ve got: So that it is text that has “Next Post: Blah” when you hold the mouse over.

adam
Comment » November 3, 2006 @ 5:15 pm

Regarding:

ahhhh disregard…… looks like all ya gotta do is plug in inside the call to post_nav_link :)

Can you explain how to do this? I’m trying to use this plugin in my Main Index template so I can have a link back to our previous day’s post.

Thanks!

Eric
Comment » December 28, 2006 @ 1:50 am

Thanks a bunch for the plug in. Had a little trouble with the get image size function, so I just removed it. Otherwise, it saved me a bunch of trouble. Thanks again.

Derek
Comment » March 7, 2007 @ 4:35 am

I managed to get this working. One thing I noticed though was that when I browse previous and next on single pages, it also see’s pages. Any updates for this?

Jai
Comment » November 27, 2008 @ 8:07 am

Hello Friend.. First of all I do not know if u still supporting this plugin or not..
I am having a problem while using it.. The problem is .. The first blog entry instead of showing a no latest button is treating my contact page as a post entry and is showing it as latest entry and hence a latest button appears..
Cud u plz help me with this..

Jeremy
Comment » January 7, 2009 @ 1:29 pm

Thanks for this plug in – it’s exactly what I wanted to do on my pages, but one issue I’m having is that it’s treating my custom pages like posts… is there any way to exclude page from being pulled in as the next and previous posts?

You can see the issue here… http://www.jjsewell.com/blog/?p=51 – when I click previous, it goes to my contact page which was created in between the creation of two posts… is there any way to avoid this?

obert
Comment » January 26, 2009 @ 1:15 pm

Hello, I am trying to customize the output of this plugin http://wordpress.org/support/topic/43071#post-242006 but i don’t really get the usage. Mainly I won’t to have ‘Previous link: ‘ and ‘Next link: ‘ in front of the title link, so how to use those param?
Thanks a lot for help.
Regards

 

* Required field (e-mail is not published). Breaks and paragraphs are automatic. HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>