Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I nest Next and Previous link in a href attribute that has a class and background image in a single post page?

I want to make it something like the below which is not working.

<a class="next" href="<?php echo $prev; ?>">Previous</a>
<a class="prev" href="<?php echo $next; ?>">Next</a>

Here is the link to a sample site: http://ifunnypic.com/dad-i-m-gay_3317.html

Thanks

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

EDIT

In single.php you should be using: <?php previous_post_link('%link', 'Previous'); ?> and <?php next_post_link('%link', 'Next'); ?>. Then you add this to your functions.php:

function filter_next_post_link($link) {
    $link = str_replace("rel=", 'class="next" rel=', $link);
    return $link;
}
add_filter('next_post_link', 'filter_next_post_link');

function filter_previous_post_link($link) {
    $link = str_replace("rel=", 'class="prev" rel=', $link);
    return $link;
}
add_filter('previous_post_link', 'filter_previous_post_link');

Although this is not the answer to this question, but to paginate in categories you should be looking into next_posts_link_attributes and previous_posts_link_attributes hooks. Just add this to your functions.php:

function next_posts_link_css($content) { 
    return 'class="next"';
}
function previous_posts_link_css($content) { 
    return 'class="prev"';
}

add_filter('next_posts_link_attributes', 'next_posts_link_css' );
add_filter('previous_posts_link_attributes', 'previous_posts_link_css' );

Just to clarify. You'll be using the usual pagination in your template files:

<?php previous_posts_link('Previous') ?>
<?php next_posts_link('Next') ?>
share|improve this answer
    
Hi, @daniel-sachs I tried it, but nothing showed up in the single post page. To make it more clear here is the sample link: ifunnypic.com/dad-i-m-gay_3317.html –  FlourishDNA Jul 7 '12 at 21:54
1  
hmmm, sorry,I missed the "single post" part. In single.php you should be using: <?php previous_post_link('%link', 'Previous'); ?> and <?php next_post_link('%link', 'Next'); ?> . Then you add this to your functions.php: function filter_next_post_link($link) { $link = str_replace("rel=", 'class="next" rel=', $link); return $link; } add_filter('next_post_link', 'filter_next_post_link'); function filter_previous_post_link($link) { $link = str_replace("rel=", 'class="prev" rel=', $link); return $link; } add_filter('previous_post_link', 'filter_previous_post_link'); –  Daniel Sachs Jul 7 '12 at 23:50
    
Thanks @Daniel Sachs It worked. Cheers. –  FlourishDNA Jul 9 '12 at 22:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.