2

自定义类型帖子中的分页代码

<?php  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // For pagination

$loop = new WP_Query( array('post_type' => 'Portfolio','posts_per_page' => 3,'orderby'=> 'menu_order',
'paged'=>$paged ) ); ?> //For implementing pagination
<?php if ($loop->have_posts()): ?>
<?php while ($loop->have_posts()) : $loop->the_post(); ?> <div id="latestproimg">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_post_thumbnail('large', array('title' => false)); ?></a>
</div>
<div id="latestpostser">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark">
<?php echo get_the_title(); ?></a></h2> //displaying the title
<?php //echo get_the_excerpt(); ?>
<?php //the_content( 'Read the full post »' ); ?> // for displaying the content
</div>
<div class="clr"></div>
<?php endwhile;
endif; ?>

请告诉我代码中的错误在哪里

4

2 回答 2

1

即使我已经放置了 $page 选项,我也遇到了这个奇怪的分页问题,​​但是解决了我的问题的方法是尝试将分页参数更改为get_query_var 函数的页面

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1; // For pagination

让我知道它是否有效

于 2012-11-06T13:41:37.080 回答
0

get_query_var('paged')如果永久链接设置将 url 更改为类似http://domain.com/page/2/.... 因此,@IoQ 答案的更灵活版本是,

$search_values['paged'] = (get_query_var('paged')) ? get_query_var('paged')
: ((get_query_var('page')) ? get_query_var('page') : 1);

如果永久链接设置为类似 postname 或是paged=xxurl 的一部分,则此方法有效

于 2014-06-18T17:00:14.057 回答