Enlaces Anterior/Siguiente para Custom Post Type
Tengo un custom post type llamado portfolio. Necesito enlaces de anterior/siguiente SIN usar un plugin. ¿Alguien tiene una solución?
Ejemplo de entrada: http://themeforward.com/demo2/archives/portfolio/boat
<?php get_header(); ?>
<!-- Inicio del contenedor -->
<div class="clear">
<div id="full_container">
<div id="content2">
<div id="content">
<!-- Obtener entradas -->
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<!-- Título de la entrada -->
<h1>
<?php the_title(); ?>
</h1>
<!-- La entrada -->
<?php the_content(); ?>
<!-- Etiquetas -->
<h3 class="tags">
<?php the_tags('Etiquetas ',' / ','<br />'); ?>
</h3>
<!-- Fin del contenedor -->
</div>
<!-- Entradas Anterior/Siguiente -->
<div class="mp_archive2">
<div id="more_posts">
<div class="oe">
<?php previous_post_link('%link', '« Entrada anterior', TRUE); ?>
</div>
<div class="re">
<?php next_post_link('%link', 'Entrada siguiente »', TRUE); ?>
</div>
</div>
</div>
<?php endwhile; else: ?>
<p>No se encontraron entradas coincidentes.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>

<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" ">« Entrada anterior<br /><strong>"'. $prev_title . '"</strong></a>' . "\n";
}
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" ">Siguiente entrada »<br /><strong>"'. $next_title . '"</strong></a>' . "\n";
}
?>

Si necesitas enlaces de siguiente/anterior para publicaciones individuales, WordPress incluye las funciones incorporadas next_post_link
y su correspondiente previous_post_link
, las cuales probablemente deberían usarse dentro del loop.
Para archivos, utiliza next_posts_link
y previous_posts_link
.
Todas estas funciones funcionarán correctamente con tipos de publicaciones personalizados (custom post types).

Vale. Bueno, sin ver tu código, es difícil decir por qué. ¿Hay algún error o advertencia en PHP? ¿Has insertado múltiples entradas para que las funciones obtengan los enlaces?

Usa esto <?php next_post_link('%link', 'Next post »'); ?>
y <?php next_post_link('%link', 'Next post »'); ?>

Esto funciona en tipos de posts personalizados, pero ¿qué pasa con la misma taxonomía del post actual?

@jepser (Llegando tarde a la fiesta aquí) Necesitarías especificar la taxonomía a usar como quinto argumento. Si solo pasas los primeros 3 argumentos y habilitas el tercero para mantener la misma taxonomía, probablemente falle porque la taxonomía por defecto es category
(que probablemente tu CPT no tenga). Consulta los artículos del codex enlazados en la respuesta.

Puedes usar get_adjacent_post
para obtener el objeto de la publicación anterior o siguiente en el bucle.
Puedes cambiar el tercer parámetro a verdadero o falso para obtener el objeto de la publicación siguiente o anterior. get_adjacent_post( false, '', true);
Con este conocimiento podemos usar get_the_permalink
para obtener la URL de las publicaciones y crear tus propios enlaces, sin necesidad de eliminar basura que WordPress agrega en otros métodos.
Este método es más útil si deseas estilizar los hipervínculos tú mismo y tener control total sobre el formato.
<?php
$next_post = get_adjacent_post( false, '', false);
$next_post_url = get_the_permalink($next_post);
$previous_post = get_adjacent_post( false, '', true);
$previous_post_url = get_the_permalink($previous_post);
?>
<a href="<?php echo $next_post_url;?>">Siguiente publicación</a>
<a href="<?php echo $previous_post_url;?>">Publicación anterior</a>

Adicionalmente, si deseas tener un bucle continuo de publicaciones puedes usar esto: https://wplancer.com/infinite-next-and-previous-post-looping-in-wordpress/
