Adding images to the previous post and next post links in WordPress can enhance the look of your website. To add image links for a single blog post, just use previous_post_link and next_post_link and add any images and text you want to use as arguments:


<div class="prev-posts"><?php previous_post_link('%link','<p><img src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/left.png" /> &nbsp; Previous Post</p>'); ?></div>

<div class="next-posts"><?php next_post_link('%link','<p>Next Post &nbsp; <img src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/right.png" /></p>'); ?></div>

To add image links to a list of items returned, such as search results, archives, categories and tags, you can use posts_nav_link, which takes three arguments, the separator between the left and right link, the left text and/or images and the right text and/or images. This will enable moving between pages of results returned.

<?php endwhile; ?>

<?php posts_nav_link( ' -- ', '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/left.png" />' . ' Back to Previous Results', 'More Results ' . '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/right.png" />' ); ?>

If unsure as to which file controls a particular set of results, you can refer to the template hierarchies in the WordPress codex. To check the hierarchy for categories and tags, you can refer to Category Templates and Tag Templates.

Tags: , , , , ,

In categories: web development



Only the name field is required. Your email will not be published.