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 am using a custom page template for my portfolio. The code is calling the correct number of posts per page but for some reason the pagination links won't show up :-S

My query

<?php 
    $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 2)); 
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   
    $custom = get_post_custom($post->ID);
    $screenshot_url = $custom["screenshot_url"][0];
    $website_url = $custom["website_url"][0];
?>

The entire markup

<?php
/*
Template Name: Portfolio
*/
?>

<?php get_header(); ?>

<div id="full_container">
<div id="portfolio_content">
<div id="portfolio_wrap">
<div id="content">

    <?php 
        $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 2)); 
    ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php   
        $custom = get_post_custom($post->ID);
        $screenshot_url = $custom["screenshot_url"][0];
        $website_url = $custom["website_url"][0];
    ?>


<a href="<?php the_permalink() ?>">

<span class="img">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-portfolio' ); } ?>

<span class="under">
<!-- Excerpt title -->
<span class="title"><?php the_title(); ?></span>

<!-- Excerpt description -->
<span class="desc">
    <?php my_excerpt('short'); ?>
</span>
</span>
</span>
</a>


        <?php endwhile; ?>  

<!-- Next/Previous Posts -->
<?php if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
} ?>

</div>
</div>
</div>
</div>
</div>

<?php get_footer(); ?>
share|improve this question
    
You should show the code inside pagination();... –  kaiser Oct 9 '11 at 17:33
    
Switch to using query_posts and your problems will vanish, the pagination functions are designed to work with the main loop, and specifically look to $wp_query to determine how many pages there are and whether to page, etc (your pagination function may be doing the same, i'm not familiar with whicever plugin provides that though).. see here. –  t31os Oct 10 '11 at 18:00
add comment

2 Answers

up vote 0 down vote accepted
<?php
/*
Template Name: Portfolio
*/
?>

<?php get_header(); ?>

<div id="full_container">
<div id="portfolio_content">
<div id="portfolio_wrap">
<div id="content">

    <?php 
        $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 2)); 
    ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php   
        $custom = get_post_custom($post->ID);
        $screenshot_url = $custom["screenshot_url"][0];
        $website_url = $custom["website_url"][0];
    ?>


<a href="<?php the_permalink() ?>">

<span class="img">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-portfolio' ); } ?>

<span class="under">
<!-- Excerpt title -->
<span class="title"><?php the_title(); ?></span>

<!-- Excerpt description -->
<span class="desc">
    <?php my_excerpt('short'); ?>
</span>
</span>
</span>
</a>
<?php previous_posts_link('Previous'); ?> / <?php next_posts_link('Next') ?>

        <?php endwhile; ?>  

<?php if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
} ?>

</div>
</div>
</div>
</div>
</div>

<?php get_footer(); ?>
share|improve this answer
    
This isn't working, sadly. –  AndrettiMilas Oct 9 '11 at 18:17
    
wait let me check maybe i did any mistake in typing –  Mohit Bumb Oct 9 '11 at 18:18
    
okay find out mistake i post those codes out of loop before which doesn't work –  Mohit Bumb Oct 9 '11 at 18:32
    
I'm not exactly sure what you're saying. –  AndrettiMilas Oct 9 '11 at 19:15
    
previous_posts_link() next_posts_link() –  Mohit Bumb Oct 9 '11 at 19:18
show 1 more comment

I don't see the variable $additional_loop being set anywhere in your code. If you're comfortable with WP-Pagenavi, install it and modify your code as follows:

<?php
    //You need to handle the 'paged' query var for pagination!
    $paged = (get_query_var('paged'))?get_query_var('paged'):1;
    $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 2, 'paged' => $paged)); 
?>

Replace the following:

<!-- Next/Previous Posts -->
<?php if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
} ?>

With:

<?php
    if(function_exists('wp_pagenavi'))
    { 
        wp_pagenavi(); 
    }
    else
    { ?>
        <div class="navigation">
        <div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
        <div class="alignright"><?php previous_posts_link('Next entries') ?></div>
        </div>
    <?php }
?>

Hope this helps!

share|improve this answer
    
I'd rather just keep the pagination I have built into my theme right now... suggestion? –  AndrettiMilas Oct 9 '11 at 16:44
    
Might have to see how your pagination function works! –  Rutwick Gangurde Oct 10 '11 at 3:52
add comment

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.