2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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?

5441 posts
  • Author Level 11
  • Moderator
  • Winner
  • 6 Years of Membership
+20 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

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says

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

165 posts
  • Trendsetter
  • Elite Author
  • Author Level 8
  • Most Wanted Winner
+4 more
AnarielDesign
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.
2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says

duplicate

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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 ;)
394 posts icypixels.com
  • Weekly Top Seller
  • Winner
  • Elite Author
  • Author Level 8
+7 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

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says

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

Any other ideas?

416 posts
  • United States
  • Power Elite Author
  • Trendsetter
  • Top Monthly Author
+8 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() ) : .

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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