2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 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?

3303 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker 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

2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 more
revaxarts says

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

162 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Won a Most Wanted contest
  • Has been part of the Envato Community for over 3 years
+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.
2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 more
revaxarts says

duplicate

2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 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 ;)
295 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
  • Has been part of the Envato Community for over 2 years
+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

2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 more
revaxarts says

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

Any other ideas?

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

2184 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 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() )

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by