WordPress: previous_post_link() sits on top, after div “entry-content”, no matter where I place it

I have installed a plugin which is custom post type, I am trying to use the previous_post_link() and next_post_link() to get previous and next posts.

It is working fine but the only problem is that I am placing it in my 4th div container where as it always sits on top of page right after div "entry-content".

Read More

Is it a known issue?

Here is the piece of code:

function some_function () {

global $post;

    if ('team' == get_post_type() && is_single() && in_the_loop()) {
        $fields = WPMTPv2_OPTIONS()->fields;
        $meta = WPMTPv2_FIELDS($post->ID);

        $tmp = '<div id="wpmtp-single-wrap">';
        $tmp .= '<div class="wpmtp-vcard">';
        $tmp .= '<div class="wpmtp-vcard-left">';

        $tmp .= wpmtpv2_featured_img($post->ID);

        $previous   = previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
        $next       = next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
//        $tmp .= '<a href=""><div class="wpmtp-goback">go back</div></a>';
//        $tmp .= '<a href=""><div class="wpmtp-gonext">view next</div></a>';

        $tmp .= $previous;
        $tmp .= $next;

        $tmp .= '</div>';

...........
..........
..........
........

return $tmp;

}

If I place the commented html code instead or previous and next functions, it works fine. Which mean that html and css are right in place, and the problem is in the functions I guess.

And this is what I get after inspecting it in firebug:

<article .....>
<h2 .....></h2>
<div class="meta"></div>
    <div class="entry-content">

        <a href="link to next" rel="prev">
                    <div class="wpmtp-gonext">view next</div>
                </a>
    <a href="link to previous" rel="next">
        <div class="wpmtp-goback">go back</div>
    </a>
    <div id="wpmtp-single-wrap">
        <div class="wpmtp-vcard">
            <div class="wpmtp-vcard-left">
.....
....
....
....

Related posts

Leave a Reply

1 comment

  1. try this code:

        <?php
        function some_function () {
    
        global $post;
    
            if ('team' == get_post_type() && is_single() && in_the_loop()) {
                $fields = WPMTPv2_OPTIONS()->fields;
                $meta = WPMTPv2_FIELDS($post->ID);
        ?>
                <div id="wpmtp-single-wrap">
                   <div class="wpmtp-vcard">
                      <div class="wpmtp-vcard-left">
                         <?php echo wpmtpv2_featured_img($post->ID); ?>
                         <div class="wpmtp-goback"><?php previous_post_link( '%link', __( ' go back', 'twentyeleven' ),TRUE ); ?></div>
                         <div class="wpmtp-gonext"><?php next_post_link( '%link', __( 'view next', 'twentyeleven' ),TRUE ); ?></div>
                             <?php      
                             // replace **twentyeleven** with your theme name
                             //or try with this line
                             //previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');   
                             //next_post_link('%link', '<div class="wpmtp-goback">go back</div>');                       
                            ?>               
                </div>
        <?php        
        .........
        .........
        ........
    
        return $tmp;
    
        }
    

    or best to try this plugin : wp-pagenavi

    This plugin provides the wp_pagenavi() template tag which generates fancy pagination links.

    thanks