admin管理员组文章数量:1333689
I'm on single-work.php
for a custom post type called work
, inside the loop.
Trying to make two links to the previous and next post.
Using this code:
<?php previous_post_link(); ?>
and
<?php next_post_link(); ?>
But nothing shows up. Am I missing something
Here is my code, very straightforward:
<?php get_header(); ?>
<div class="full" >
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php endwhile; // end of the loop. ?>
</div><!--/full-->
<?php get_footer(); ?>
I'm on single-work.php
for a custom post type called work
, inside the loop.
Trying to make two links to the previous and next post.
Using this code:
<?php previous_post_link(); ?>
and
<?php next_post_link(); ?>
But nothing shows up. Am I missing something
Here is my code, very straightforward:
<?php get_header(); ?>
<div class="full" >
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php endwhile; // end of the loop. ?>
</div><!--/full-->
<?php get_footer(); ?>
Share
Improve this question
edited Dec 13, 2012 at 20:58
wesbos
asked Dec 13, 2012 at 20:47
wesboswesbos
2432 gold badges5 silver badges10 bronze badges
3 Answers
Reset to default 4What I see in your code is that your next post and previous post codes are appearing within the while loop which shouldn't be within the loop and it should appear like this:
<?php get_header(); ?>
<div class="full" >
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php endwhile; // end of the loop. ?>
<?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>
</div><!--/full-->
<?php get_footer(); ?>
Or, you can find it in detail here.
In the above post I found numeric pagination but still it have explained how exactly the pagination works, which is in great detail.
Read the documentation.
This function will not work (fail silently) if mysql.trace_mode is enabled in your php.ini. If you can't edit that file, try adding
ini_set( 'mysql.trace_mode', 0 );
to your theme's functions.php.
That might solve your problem, it did for me.
The functions are right; set the params
<?php next_post_link('%link', 'Next post »'); ?>
<?php next_post_link('%link', 'Next post »'); ?>
Well, without seeing any of your code, it's hard to say why. Are there any PHP errors or warnings?
Update
A small example
<?php query_posts( array( 'post_type' => 'page', 'post_status' => 'publish' ) ) ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post() ?>
<!-- do stuff -->
<div id="nav-single">
<div class="left"><?php previous_post_link(); ?></div>
<div class="right"><?php next_post_link(); ?></div>
</div>
<?php endwhile; // end of the loop. ?>
<?php wp_reset_query(); ?>
<?php else : ?>
<!-- do other stuff here -->
<?php endif ?>
本文标签: previouspostlink() and nextpostlink() with a custom post type
版权声明:本文标题:previous_post_link() and next_post_link() with a custom post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742339420a2456294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论