0

I used single.php for this code:

<?php $categories = get_the_category($post->ID);
if ($categories) {
    $category_ids = array();
    foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
    $args=array(
        'category__in' => $category_ids,
        'post__not_in' => array($post->ID),
        'showposts'=>6, //Gösterilecek yazı adeti
        'caller_get_posts'=>1
    );
    $benzer = new wp_query($args);
    if( $benzer->have_posts() ) {
        while ($benzer->have_posts()) {
            $benzer->the_post();
    ?>
    <div class="urundetaykutu">
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </div>  
    <?php } } wp_reset_query(); }?>

This code working, but I want to use pagination in the loop.

1 Answer 1

2

Try adding

'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, // this will get the right posts for the current page (i.e. if the user loads www.domain.com/blog/page/2 directly)
'posts_per_page' => '6'

to your $args and delete showposts

showpostsis deprecated.

From the Codex reference for WP_Query:

showposts (int) - number of posts to show per page. Deprecated as of Version 2.1 in favor of 'posts_per_page'.

Add Pagination links:

<?php next_posts_link( '&larr; Older posts' ); ?>
<?php previous_posts_link( 'Newer posts &rarr;' ); ?>
3
  • ok, but pagination not work. Only, three posts show. I want to do paging in this code.
    – Mehmet Alp
    Oct 15, 2012 at 13:57
  • You have to add pagination links. I've edited the answer. Working now?
    – xsonic
    Oct 15, 2012 at 13:59
  • add pagination links but not work. added(pagination links) to the bottom of the code. here after; <?php } } wp_reset_query(); }?> '<?php next_posts_link( '&larr; Older posts' ); ?> <?php previous_posts_link( 'Newer posts &rarr;' ); ?>'
    – Mehmet Alp
    Oct 15, 2012 at 14:31

Your Answer

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

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