2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 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?

3061 posts
  • Located in Australia
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
  • Helped several times protecting Envato Market against copyright violations
+16 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

2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says

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

162 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+3 more
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.
2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says

duplicate

2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 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 ;)
271 posts New Elite in Town!
  • Won a competition
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Won a Most Wanted contest
+6 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

2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says

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

Any other ideas?

391 posts
  • Located in United States
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Made it to the Authors' Hall of Fame
+4 more
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() ) : .

2025 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 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