2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

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?

2823 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

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

2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

Yep, I found that thread (Google is my friend) but it wont work with @rafaelxy approach :(

162 posts
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Referred between 10 and 49 users
  • Europe
  • Bought between 100 and 499 items
  • Has been a member for 2-3 years
  • Microlancer Beta Tester
anariel7 says

Yep, I found that thread (Google is my friend) but it wont work with @rafaelxy approach :(
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.
2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

duplicate

2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

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 ;)
248 posts New Elite in Town!
  • Won a Competition
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Most Wanted Bounty Winner
  • Microlancer Beta Tester
  • Romania
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 10 and 49 items
+1 more
icypixels says

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

2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

@icypixels get_next_post() is always null so the condition is always false.

Any other ideas?

380 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Referred more than 2000 users
  • Bought between 500 and 999 items
  • Has been a member for 4-5 years
  • Exclusive Author
  • United States
WPExplorer says

@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() ) : .

2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

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() )

by
by
by
by
by
by