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.

I believe this is completely different than the question asked here.

I'm adding pagination to my theme using a filter hook. The output appears at the beginning and end of my content, rather than just the end.

My function, in the template's functions.php file:

add_filter('the_content','pagination_after_post',1);
/**
 * Adds pagination after the post
 *
 * @uses is_single()
 */

function pagination_after_post($content){
    if( is_single() ){
        $content .= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous') . '</div>';
        return $content;
    } // if
} // pagination_after_post

Here is my single.php:

<?php get_header(); ?>

        <div id="centercol">

        <?php if (have_posts()) : ?>

            <?php while (have_posts()) : the_post(); ?>



                <div class="post" id="post-<?php the_ID(); ?>">

                    <h2 class="singleh2"><a title="<?php _e('Permanent Link to',woothemes); ?> <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <div class="date-comments">
                        <p class="fl"><?php the_time('l, M j, Y \a\t g:i a'); ?> by <a href="<?= get_author_posts_url( get_the_author_meta( 'ID' ) ) ?>" rel="author"><?= get_the_author() ?></a></p>
                        <p class="fr"><?php the_category(', ') ?></p>                                                 
                    </div>        

                    <div class="entry">
                        <?php echo woo_get_embed('embed','500','360','video-post'); ?>
                        <?php the_content(__('<span class="continue">Continue Reading</span>',woothemes)); ?>                       
                    </div>

                    <?php the_tags('<p>Tags: ', ', ', '</p>'); ?> 

                </div><!--/post-->          

                <div id="comments">
                    <?php comments_template(); ?>
                </div>

        <?php endwhile; ?>

        <div class="navigation">
            <div class="alignleft"><?php previous_post_link(); ?></div>
            <div class="alignright"><?php next_post_link(); ?> </div>
        </div>      

    <?php endif; ?>                         

        </div><!--/centercol-->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

And a screenshot of the issue:

enter image description here

share|improve this question
    
in your functions.php did you added action hook? –  ntechi Sep 14 '11 at 18:15
    
oops you need to add add_filter –  ntechi Sep 14 '11 at 18:16
    
@ntechi I've got add_filter('the_content','pagination_after_post',1); on the first line. Anything more than that? –  hookedonwinter Sep 14 '11 at 18:17
    
check my answer –  ntechi Sep 14 '11 at 18:20

2 Answers 2

up vote 1 down vote accepted

you need to set the 'echo' parameter of wp_link_pages() to 'echo=0'; example:

$content .= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous&echo=0') . '</div>';
share|improve this answer
    
Thank you! That worked splendidly. –  hookedonwinter Sep 14 '11 at 21:21

You need to do something like this

add_filter ('the_content', 'pagination_after_post',1);
function pagination_after_post($content) {
   if(is_single()) {
      $content.= '<div class="pagination">' . wp_link_pages('before=&after=&next_or_number=next&nextpagelink=Next&previouspagelink=Previous') . '</div>';

   }
   return $content;
}
share|improve this answer
    
How is this different from what I posted, besides the lack of a comment between the add_filter and the function? –  hookedonwinter Sep 14 '11 at 18:24
    
Oh, the return is outside the if. Trying now. –  hookedonwinter Sep 14 '11 at 18:26
    
Moved the return outside the if single. The issue persists. It's not that I have 0 returned results, it's that I have two, one before and one after the content. It feels like it's doing "pagination" . $content . "pagination". –  hookedonwinter Sep 14 '11 at 18:29

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.