【发布时间】:2014-10-24 05:32:39
【问题描述】:
这是我在wordpress中列出自定义帖子类型帖子的代码,但它不起作用分页我在这里犯的错误有什么可以帮助的吗??
<div id="talent-main">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array('post_type' => 'talent','posts_per_page' => 2,'paged'=>$paged));
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('multiple') ?>>
<div class="post-image-talent">
<a class="post-frame <?php the_ID(); ?>" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"></a>
<?php the_post_thumbnail('video-talent-thumb'); ?>
</div>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_short_title('', '...', true, '22') ?></a></h2>
</div>
<?php endwhile;?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
</div> <!-- main -->
【问题讨论】:
-
您是否收到 404 错误?通常,分页的 404 错误是由于您的帖子类型共享相同的帖子或页面名称。因此,如果您有一个页面/日历和一个名为“日历”的帖子类型,它会在尝试分页时抛出 404,因为 WordPress 无法确定要显示的内容。
-
不显示前 2 个帖子没有分页工作@lan
-
你有多少帖子?我假设超过2个?如果您只有两个,那么它会显示的全部内容...此外,此页面上是否正在执行其他查询?如果是这样,您可能需要在 endwhile 之后添加 wp_reset_query;让事情再次运作codex.wordpress.org/Function_Reference/wp_reset_query
标签: wordpress pagination custom-post-type