1

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

EDITED:

See what I edited the code.

<?php 

function nextprev() {

?>
  <div class="alignleftfp">
                        <?php next_post_link('%link', '<img class="imgalign" src="' . WP_PLUGIN_URL . '/testplugin/assets/type1/5.png" alt="Next" /> %title'); ?>
                    </div>
                    <div class="alignrightfp">
                        <?php previous_post_link('%link', '%title <img class="imgalign" src="' . WP_PLUGIN_URL . '/testplugin/assets/type1/6.png" alt="Next" />'); ?>
                    </div>

<?php
$content = get_the_content(); 
 echo $content;
}

add_action('the_content','nextprev');
?>

1 Answer 1

2

You can do it like so, I guess:

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

PS. You shouldn't use next_post/previous_post functions - they're deprecated.

EDIT

Just read the_content filter docs. It SHOULD NOT echo anything. It should return it's value. So your function should look like this:

function nextprev($content) {
    ob_start(); ?>
    <div class="alignleftfp">
        <?php next_post_link('%link', '<img class="imgalign" src="' . WP_PLUGIN_URL . '/testplugin/assets/type1/5.png" alt="Next" /> %title'); ?>
    </div>
    <div class="alignrightfp">
        <?php previous_post_link('%link', '%title <img class="imgalign" src="' . WP_PLUGIN_URL . '/testplugin/assets/type1/6.png" alt="Next" />'); ?>
    </div>
    <?php $my_next_prev = ob_get_contents(); ob_end_clean();

    return $content . $my_next_prev;
}

add_action('the_content','nextprev');
9
  • Thanks When i Use the condition with add_action hook to the_content the existing content disappear. So I use get_the_content(); still i have an problem that link comes top of the post. I use echo to get the content also i tried the return option to get the content still blank post with corresponding post happen Jul 12, 2013 at 9:24
  • You shouldn't use it inside the_content hook, but in template file. If you really have to do it with the_template hook, just make sure you return it and not output it... the_content filter should NOT output anything. It should return the value. Jul 12, 2013 at 9:28
  • Thanks For Awesome Response. I edited the code. I am Not sure I tried to create the custom plugin. I tried the_content hook with echo of get_the_content(); , also i tried the return option still nothing happen. Any Idea Jul 12, 2013 at 9:33
  • Updated my answer. Jul 12, 2013 at 9:42
  • Thanks it works but it should look like previous post and the nextpost link is appear top of the content ? why Jul 12, 2013 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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