Use the ‘internal’ WordPress function get_previous_post() (there’s a get_next_post() as well). You probably want to assign it to a var:
$prev_post = get_previous_post();
There’ll be two properties to $prev_post:
$prev_post->ID
$prev_post->post_title
For the url, you can pass the previous post’s ID to get_permalink():
get_permalink($prev_post->ID);
Note: Make certain to first scope the $post object to global in your plugin’s function(s); it’ll be needed to know what the previous and next posts are meant to be in relation to.
hello
thank you for your answer Kafkaesqui
I’ve started trying to get what i want with your reply, but i dont know how, i found the code of the previous_post_link function in the link-template.php file, and i changed it in order to get what i want :
function my_previous_post_link($format=’%link’, $link=’%title’, $in_same_cat = false, $excluded_categories = ”) {
if ( is_attachment() )
$post = & get_post($GLOBALS[‘post’]->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories);
if ( !$post )
return;
$title = apply_filters(‘the_title’, $post->post_title, $post);
$string = ‘&prev_id=’.$post->ID.’&prev_link=’.get_permalink($post->ID).’&prev_title=’.$post->post_title;
echo $string;
}
do you think this is correct ? it works perfectly for me, though i’m not really making it reusable for another purpose… for example, i’m not using the first two parameters, because i dont need any other usage of this function…
and i dont know what’s the use of the apply_filter function, i think maybe i can remove it in my_previous_post_link function…
i hope this will be useful for other people !
thanks bye
Speed DARYL http://www.speed-daryl.com