不显示下一个和上一个(在本例中为分页)

时间:2011-10-09 作者:AndrettiMilas

我正在为我的公文包使用自定义页面模板。代码正在调用每页的正确帖子数,但由于某些原因,分页链接不会显示:-S

我的查询

<?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];
?>
整个标记

<?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(); ?>

2 个回复
最合适的回答,由SO网友:Mohit Bumb 整理而成
<?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(); ?>
SO网友:Rutwick Gangurde

我看不到变量$additional_loop 在代码中的任意位置设置。如果你对WP-Pagenavi, 安装它并修改代码,如下所示:

<?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)); 
?>
更换以下部件:

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

<?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 }
?>
希望这有帮助!

结束