Popular post

About

Blog sobre diseño y desarrollo web.
Códigos o enlaces que me han sido útiles en mi trabajo como desarrolladora web :)

viernes, 30 de diciembre de 2016

WordPress Custom Post Type Pagination Issue

Código para el template

<!-- Archivo de cabecera global de Wordpress -->
<?php get_header();
/**
 * Template Name: Portfolio
 **/
?>
<?php get_header(); ?>

<h2>Posts</h2>

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

query_posts(array(
'post_type'      => 'portfolio', // You can add a custom post type if you like
'paged'          => $paged,
'posts_per_page' => 2
));

if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post(); ?>

 <article class="loop">

<div class="thumbnail">
 <?php
 if ( has_post_thumbnail() ) {
the_post_thumbnail('square-thumb');
 }
 ?>
</div>
<div class="content">

<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<small>Publicado el <?php the_time('j/m/Y') ?> por <?php the_author_posts_link() ?> | <?php the_taxonomies( $args ); ?>

  </small>


</div>
      </article>
<?php endwhile; ?>

<?php my_pagination(); ?>

<?php else : ?>

    <p><?php _e( 'Ups, no hemos encontrado ningún post.' ); ?></p>

<?php endif; ?>

<?php get_footer(); ?>




Código en fuctions.php

//paginacion para query loop
if ( ! function_exists( 'my_pagination' ) ) :
function my_pagination() {
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
endif;

Tuve un problema y me daba error 404 la paginación.. la respuesta... llama a tu página de manera diferente a tu custom post type.

http://www.qwerty-design.co.uk/2015/02/wordpress-custom-post-type-pagination-issue/