分页链接不显示

时间:2011-10-30 作者:Ben

我无法显示“next\\u posts\\u link()”和“previous\\u posts\\u link()”。到目前为止,我已经通过停用所有插件并清除缓存尝试了标准的第一次调试,还尝试了从调用中删除可选参数。我也尝试过使用wp pagenavi,它确实会显示,但奇怪的是,只有当我将阅读选项设置为每页显示1篇文章,甚至只显示2个页面链接时,它才会显示。我遇到的问题是pixelsandtea.com 这是我的主页模板页面上的代码。

<?php get_header(); ?>
<div id="main-inner">
<ul class="mcol" id="mcol">
        <?php
            $args = array( \'post_type\' => array( \'post\', \'portfolio\', \'news\' ) );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();
        ?>
        <li class="article preview" id="post-<?php the_ID(); ?>">
            <h2 class="articleTitle"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php $content = $post->post_content;
            $searchimages = \'~<img [^>]* />~\';
            preg_match_all( $searchimages, $content, $pics );
            $iNumberOfPics = count($pics[0]);
            if ( $iNumberOfPics > 0 ) { ?>
                <a href="<?php the_permalink(); ?>" class="thumb" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo(\'template_directory\'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&w=279&zc=1" alt="<?php the_title(); ?>" /></a><?php
            }
            the_excerpt(); ?>
            <div class="postmetadata">
                Posted: <?php the_time(__(\'l, jS F, Y\')) ?>&nbsp;&#721;&nbsp;<?php printf(__(\'Filed under: %s\'), get_the_category_list(\', \')); ?>&nbsp;&#721;&nbsp;<?php the_tags(); ?><br />
                <?php comments_popup_link(__(\'No commentaries for this post yet. You could be the first!\'), __(\'1 Comment\'), __(\'% Comments\'), \'\', __(\'Comments are closed\') ); ?><?php edit_post_link(__(\'Edit this entry\'), \'&nbsp;&#721;&nbsp;\', \'\'); ?>                         
            </div>
        </li>
        <?php endwhile; ?>
        </ul>
        <div class="clear"></div> 
        <div id="nav">
            <div id="navleft"><?php next_posts_link() ?><div class=\'clear\' style=\'clear:left;\'></div></div>
            <div id="navright"><?php previous_posts_link() ?><div class=\'clear\' style=\'clear:right;\'></div></div>
        </div>
</div>
<?php get_footer(); ?>
谢谢你了!

2 个回复
SO网友:Chip Bennett

您需要进行一些“黑客”操作,才能使分页为自定义循环工作。

定义之后$loop, 执行以下操作:

<?php
// globalize $wp_query
global $wp_query;
// copy $wp_query into a temporary variable
$temp_wp_query = $wp_query;
// nullify $wp_query
$wp_query = null;
// move $loop into $wp_query
$wp_query = $loop;
?>
此时,您的posts_nav_link() 应按预期工作。

现在,在循环之后,将原始对象交换回$wp_query, 以便页面上依赖于查询的所有其他内容都能正常工作:

<?php
// restore original $wp_query
$wp_query = $temp_wp_query;
?>

SO网友:Sagive

Try replacing those next/prev tags with this:

<?php next_posts_link(\'&laquo; Older Entries\') ?>
<?php previous_posts_link(\'Newer Entries &raquo;\') ?>
结束

相关推荐

Broken category pagination

出于某种原因,下面的代码一直工作到我到达第三页并给出404。不使用任何插件就可以修复它吗?<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(\'cat=\'. $id .\'&posts_per_page=4&paged=\'.$paged); while ($wp_query->have_posts()) : $wp_query