WP plugin: Next-Previous Post IMG
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
previous_post() ones in WordPress, but have obvious differences:
<?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); ?>
- 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.
- (integer) Width (in pixels) for image as displayed. Defaults to true image width.
- (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.
- (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.
- (boolean) Use the title of next/previous post in title/alt attributes (
TRUE) or do not (
FALSE). Defaults to
(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: '); ?>