previous_post_link (8 posts)

  1. nomoregrapes
    Posted 8 years ago #

    I'm trying to use <?php previous_post_link(); ?> on a page that displays one one blog post (the latest).

    It doesn't work, but <?php the_ID(); ?> work's in the same place so I am definetly in the loop. I don't know how to troubleshoot this further to find out why it wouldn't work.

    Also these two pages contradict each other...
    "This function has been deprecated."

    "Remark : previous_post and next_post seem to be working on WP2.3."

    (Note: I have used previous_post also, aswell as trying the next equivillant of both)

    Nothing seems to work! Please can somebody help me.

  2. Austin Matzko
    Posted 8 years ago #

    Are you using <?php previous_post_link(); ?> within the same while loop as <?php the_ID(); ?>? Does this single post use a custom template that queries for only one result?

    Also these two pages contradict each other...

    Actually, being deprecated---which previous_post is---does not mean that it doesn't work. It means that it is scheduled not to work in a future release. Usually, deprecated functions sit in the wp-includes/deprecated.php file for a couple of versions before they're removed entirely, in order to give developers fair warning.

  3. nomoregrapes
    Posted 8 years ago #

    yes, the <?php previous_post_link(); ?> is right next to <?php the_ID(); ?> as in there is a line <?php the_ID(); ?>-<?php previous_post_link(); ?>.

    It's a custom page (really outside the template)
    The loop is started with

    <?php $my_query = new WP_Query('category_name=main-posts&showposts=1');
    	while ($my_query->have_posts()) : $my_query->the_post(); ?>
  4. Austin Matzko
    Posted 8 years ago #

    It could have something to do with the fact that you're instantiating the WP_Class into a custom variable, $my_query, instead of $wp_query.

    Try using this instead:

    <?php query_posts('category_name=main-posts&showposts=1');
    	while (have_posts()) : the_post(); ?>
  5. nomoregrapes
    Posted 8 years ago #

    still no luck with the previous link

  6. nomoregrapes
    Posted 8 years ago #

    I'm thinking I might have to end up doing some hack involving getting 2 posts. Like...

    while (have_posts()) : the_post();
    ...if count = 0 then
    ......output all the post stuff, then count++
    ......output link to post (labelled 'previous post')

  7. nomoregrapes
    Posted 8 years ago #

    Right the main problem seems to be that I was doing previous_post_link when it should be previous_posts_link. Doh, don't know how that changed.
    Also I need next_posts_link() as wordpress is weird and this is the latest post only.

    Trouble is it's linking to http://www.example.com/example.php/page/2
    example.com/example.php is the page it's on (not index.php, later it will be included from index.php but I would rather it worked regardless of the current file name), and '/page/2' I don't know because my blog urls are like '/2008/05/post-title'. So clearly it's not linking to the right place.

    Second trouble, I'd like link name to be the blog title but it just shows 'Next Page ยป'. Putting more than one partameter in the next_posts_link() and the link disappears completly, putting one and it shows the text but doesn't change %title or %link.

  8. plugues
    Posted 7 years ago #

    i'm having the same problem. was this ever resolved?

Topic Closed

This topic has been closed to new replies.

About this Topic