- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
I have no idea why next_post_link() and previous_post_link() doesn’t work on my custom post type:
<section id="portfolio">
<?php next_post_link(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php previous_post_link(); ?>
</section>
Any ideas?
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
Thought I had done this successfully before, but turns out it doesn’t work either.
Maybe this? http://wordpress.org/support/topic/pagination-with-custom-post-type-listing
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
Yep, I found that thread (Google is my friend) but it wont work with @rafaelxy approach 
revaxarts saidTry this:
Yep, I found that thread (Google is my friend) but it wont work with @rafaelxy approach![]()
<div class="pagination" style="margin: -20px 0 5px 60px;">
<?php previous_posts_link(__( 'Previous entries', 'anariel')); ?>
<?php next_posts_link(__( 'Next posts', 'anariel')); ?>
</div>
I have this inside mine portfolio custom page and it works, adjust margins for u.- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
duplicate
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
anariel7 said
Try this:<div class="pagination" style="margin: -20px 0 5px 60px;"> <?php previous_posts_link(__( 'Previous entries', 'anariel')); ?> <?php next_posts_link(__( 'Next posts', 'anariel')); ?> </div>I have this inside mine portfolio custom page and it works, adjust margins for u.
previous_posts_link() returns null so no need to set margins to nothing 
Hey revaxarts,
I used something like this, for a Portfolio Post Type, in single-portfolio.php:
<?php if( get_next_post() ) : ?>
<div class="nav-next"><?php next_post_link('%link ? ') ?></div>
<?php endif; ?>
<?php if( get_previous_post() ) : ?>
<div class="nav-prev"><?php previous_post_link('? %link <span> |</span>') ?></div>
<?php endif; ?>
Hope it helps.
Paul
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
@icypixels get_next_post() is always null so the condition is always false.
Any other ideas?
revaxarts said
@icypixels get_next_post() is always null so the condition is always false. Any other ideas?
The previous_post_link(); and next_post_link(); tags MUST be used within the loop and you’ve added them outside of the loop…put it before <?php endif; ?> and put the next_post_link(); inside the loop after if ( have_posts() ) : .
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
WPExplorer said
The previous_post_link(); and next_post_link(); tags MUST be used within the loop and you’ve added them outside of the loop…put it before <?php endif; ?> and put the next_post_link(); inside the loop after if ( have_posts() ) : .
Yes I thought about that – without success 
Maybe here is something wrong:
register_post_type( 'portfolio', array(
'labels' => array( /* blabla */),
'public' => true,
'can_export' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 30,
'has_archive' => false,
'hierarchical' => false,
'rewrite' => true,
'supports' => array( 'title' ),
'register_meta_box_cb' => array( $this, 'add_meta_boxes' )
);
I thought about the rewrite option and tried everything without success (always called flush_rewrite_rules() )
