Vignesh Pichamani
Vignesh Pichamani

Reputation: 8070

Next Previous Post in wordpress with previous / next link with title?

I recently tried the previous post and the next post button link. I do that with image in the left and right side of the site.Its working perfect.But i didn't know how to do this

For Example:

 <div class="alignleftfp">
                        <?php next_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no');
                        ?>
                    </div>
                    <div class="alignrightfp">

                        <?php previous_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" />  ', 'no');
                        ?>
                    </div>

Is it Possible to Show the Previous Post and Next Post Link with Under Title in every Bottom of the Post. Here is the Screenshot. enter image description here

Upvotes: 0

Views: 9100

Answers (2)

zapbuild
zapbuild

Reputation: 310

I hope you are using this code in single.php from where the whole of the post is displayed. For displaying the links (Next/Prev), you need to check the function.

get_template_part()

in the same file (Single.php of your theme). In my case function in single.php has been passes parameters like

<?php get_template_part( 'content-single', get_post_format() ); ?>

So, you will open the "content-single.php" according to the parameters specified in the function and paste the same code

<div class="alignleftfp">
<?php next_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/1.png" alt="Next" /> ', 'no');
?>
</div>

<?php previous_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/2.png" alt="Next" />  ', 'no');
?>
</div>

below <h1 class="entry-title"><?php the_title(); ?></h1>

I hope this will solve your problem.

Upvotes: 1

Ravi Patel
Ravi Patel

Reputation: 5211

<nav id="nav-single">
    <?php
        $prev_post = get_previous_post(); 
        $id = $prev_post->ID ;
        $permalink = get_permalink( $id );
    ?>
    <?php 
        $next_post = get_next_post();
        $nid = $next_post->ID ;
        $permalink = get_permalink($nid);
    ?>
       <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?> 
            <h2><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a></h2>
       </span>

       <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
            <h2><a href="<?php echo $permalink; ?>"><?php echo $next_post->post_title; ?></a></h2>

      </span>
</nav>

enter image description here

Upvotes: 3

Related Questions