<?php

//Credit for resource
//http://inchoo.net/ecommerce/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/

$category = Mage::registry('current_category');
if($category){
    $prodCol = $this->getLayout()->getBlockSingleton('catalog/product_list')->getLoadedProductCollection();
    $tool = $this->getLayout()->createBlock('page/html_pager')->setLimit($this->getLayout()->createBlock('catalog/product_list_toolbar')->getLimit())->setCollection($prodCol);
    $linkPrev = false;
    $linkNext = false;
    if ($tool->getCollection()->getSelectCountSql()) {
        if ($tool->getLastPageNum() > 1) {
            if (!$tool->isFirstPage()) {
                $linkPrev = true;
                if ($tool->getCurrentPage() == 2) {
                    $url = explode('?', $tool->getPreviousPageUrl());
                    $prevUrl = @$url[0];
                }
                else {
                    $prevUrl = $tool->getPreviousPageUrl();
                }
            }
            if (!$tool->isLastPage()) {
                $linkNext = true;
                $nextUrl = $tool->getNextPageUrl();
            }
        }
    }
    if ($linkPrev) echo '<link rel="prev" href="' . $prevUrl . '" />';
    if ($linkNext) echo '<link rel="next" href="' . $nextUrl . '" />';
}
?>

