logo

$5
go back to paged category

hi need a bit of help here

my categories are paged and I display only 6 posts per page.
I visit a post number 7 displayed on page no. 2.

I'd like to have link which takes me back to the page of category where the excerpt was displayed, in above scenario page 2.

I must not relay on js history.

6 posts per page is a static number.

how can I get a link like that?

tomasz kozysa | 04/28/10 at 11:03pm | Edit


(2) Possible Answers Submitted...

  • avatar
    Last edited:
    04/29/10
    3:37am
    Buzu B says:

    you could use the referrer of the current page and go back to that page.

    An example of this would be something like:


    <a href="<?php echo $_SERVER["HTTP_REFERER"] ?>">Back</a>


    I think that would do it.

  • avatar
    Last edited:
    04/29/10
    8:24am
    Lew Ayotte says:

    If each post is in a single category, this function could work:

    Back to <?php the_category(' ', ) ?>


    If you have several categories per post, you'll need some logic, like:

    <?php
    if (preg_match('#/category/(.*)/.*#', $_SERVER["HTTP_REFERER"], $matches)) {
    echo '<a href=' . get_category_link($matches[0] . '>Back to ' . $matches[0] . '</a>';
    }
    ?>


    Lew

    Previous versions of this answer: 04/29/10 at 5:30am

This question has expired.





Current status of this question: Completed