I am trying to display links to previous post and next post in for a custom post type regardless of whatever custom taxonomies they are attached to.

I have a custom post type called experiencecont and the single post display template as single-experiencecont.php. Here is the code that I have in the file.

 * The template for displaying all single experiencecont

<div class="headerspace"></div>
<div class="experienciaInternaContainer">

    <?php if (have_posts()) : while ( have_posts() ) :  the_post(); ?>        
    <div class="exp_wrapper">
        <div class="Bannercont">
            <?php the_post_thumbnail('full', array( 'class' => 'single_exp_banner_fi' ));?>
            <div class="Bannerconttext">
                <div class="date"><?php echo get_the_date( 'd M, Y' );?></div>
                <h3><?php echo get_the_title();?></h3>
            <div class="HighlightText"><?php echo get_the_author();?></div>
        <div class="experienciaInternadetailsCol">
            <div class="row">
                <div class="LeftCol">
                        <?php the_content();?>
                <div class="RightCol">
                    <div class="slideImg"><?php the_post_thumbnail('medium', array( 'class' => 'single_exp_slide_fi' ));?></div>
                    <div class="pagination">
                        <div class="paginationCont">
                            <div class="prev"><?php previous_post_link( '%link', '<i class="fa fa-angle-left" aria-hidden="true"></i> Anterior' ); ?></div>
                            <div class="next"><?php next_post_link( '%link', 'Siguiente <i class="fa fa-angle-right" aria-hidden="true"></i>' ); ?></div>
                            <div class="clear"></div>
            <div class="clear"></div>
    <?php endwhile; endif;?> 

    //Some other HTML stuffs here

The problem is, the previous_post_link(); and next_post_link(); functions are not returning the links to adjacent posts at all.

Where am I doing wrong?

  • Check whether exactly this template file is in use, not single.php. – Max Yudin Dec 21 '18 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.