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?
Lew Ayotte answers:
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
Buzu B answers:
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.