Agregar títulos para Anterior y Siguiente artículos de WordPress incluido thumbnails

Algunas plantillas de WordPress no consideran agregar los Títulos en sus links de navegación para los post, si conoces un poco de html sabrás que puedes agregar un poco de código y obtener los resultados que buscas.

Cabe destacar que este código incluye las imagenes pequeñas (thumbnail) que están destacadas en los artículos.

Este es el codigo para lograr mostrar los títulos de anterior y siguiente (incluido el thumbnail) y debe colocarse en el archivo single.php, abajo del contenido del post, usualmente de la función the_content();




<!-- anterior y sgte post -->
<div style="display:block;">
        <?php $prevPost = get_previous_post(true);
            if($prevPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $prevPost->ID
                );
                $prevPost = get_posts($args);
                foreach ($prevPost as $post) {
                    setup_postdata($post);
        ?>
            <div style="float:left;width:50%;">
                <a class="previous" href="<?php the_permalink(); ?>">&laquo; Anterior</a>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
                <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
            </div>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
   
            $nextPost = get_next_post(true);
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>
            <div style="float:right;width:50%;">
                <a class="next" href="<?php the_permalink(); ?>">Siguiente &raquo;</a>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
                <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
            </div>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
        ?>
 <div class="clear"></div>
    </div>
<!-- fin anterior y sgte post -->


Se puede modificar el Style aplicándolo desde los CSS para darle un diseño más agradable.




Comentarios

Publicar un comentario

Entradas populares de este blog

Superponer una imagen sobre otra con CSS

¿Ganas dinero en Facebook con Página, Grupo, Comunidad, etc?

Script para buscar palabras o textos en una página (html) con Jquery