vendredi 26 décembre 2014

Pagination not working on custom post page


I have created custom post type called



natural food



In my page-natural-food.php



<div class="main container">
<div class="content left">
<?php
$type = 'naturalfoods';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 2,
'paged'=>$paged
);

$my_query = null;
$my_query = new WP_Query($args);

if ( $my_query->have_posts()) :

while ( $my_query->have_posts()) : $my_query->the_post(); ?>

<article class="post">
<h1>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h1>

<?php the_excerpt(); ?>

<div class="readMore right">
<a href="<?php the_permalink(); ?>" class="btnReadMore">Read More&raquo;</a>
</div><!-- End readMore -->

<div class="clear"></div>
</article>
<?php endwhile;

my_simone_paging_nav();

else :
echo "<p>No content found</p>";
endif;

wp_reset_query(); // Restore global post data stomped by the_post().

?>
</div><!-- End content -->
</div><!-- End main -->
<?php get_footer(); ?>


I am using the below function in index.php


In My functions.php



if ( !function_exists( 'my_simone_paging_nav' ) ) {

function my_simone_paging_nav() {

// Don't print empty markup if there's only one page.
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
return;
}

$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
$pagenum_link = html_entity_decode( get_pagenum_link() );
$query_args = array();
$url_parts = explode( '?', $pagenum_link );

if ( isset( $url_parts[1] ) ) {
wp_parse_str( $url_parts[1], $query_args );
}

$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';

$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';

// Set up paginated links.
$links = paginate_links( array(
'base' => $pagenum_link,
'format' => $format,
'total' => $GLOBALS['wp_query']->max_num_pages,
'current' => $paged,
'mid_size' => 2,
'add_args' => array_map( 'urlencode', $query_args ),
'prev_text' => __( '&laquo;', 'my-simone' ),
'next_text' => __( '&raquo;', 'my-simone' ),
'type' => 'list',
) );

if ( $links ) :

?>
<nav class="navigation paging-navigation right" role="navigation">
<?php echo $links; ?>
</nav><!-- .navigation -->
<?php
endif;
}
}


But pagination not working





Aucun commentaire:

Enregistrer un commentaire