WordPress.org

Forums

custom post type and pagination (1 post)

  1. xilionlabs
    Member
    Posted 2 years ago #

    hi,
    i have registered a custom post type and i am trying to paginate through the saved entries.
    WP seems to find out that i have more than one page and displays the "previous" link, but when clicked, it shows a blank template page (with no loop).

    here is my custom post type code :

    // Register Custom Post Type Projets
    function sim_projets_post_type() {
    	$labels = array(
    		'name'                => _x( 'Projets', 'Post Type General Name', 'sim' ),
    		'singular_name'       => _x( 'Projet', 'Post Type Singular Name', 'sim' ),
    		'menu_name'           => __( 'Projets', 'sim' ),
    		'parent_item_colon'   => __( 'Projet parent', 'sim' ),
    		'all_items'           => __( 'Tous les projets', 'sim' ),
    		'view_item'           => __( 'Voir le projet', 'sim' ),
    		'add_new_item'        => __( 'Ajouter un projet', 'sim' ),
    		'add_new'             => __( 'Ajouter', 'sim' ),
    		'edit_item'           => __( 'Editer un projet', 'sim' ),
    		'update_item'         => __( 'Modifier un projet', 'sim' ),
    		'search_items'        => __( 'Chercher un projet', 'sim' ),
    		'not_found'           => __( 'Aucun projet trouvé', 'sim' ),
    		'not_found_in_trash'  => __( 'Aucun projet trouvé dans la corbeille', 'sim' ),
    	);
    
    	$rewrite = array(
    		'slug'                => 'nos-projets',
    		'with_front'          => true,
    		'pages'               => true,
    		'feeds'               => true,
    	);
    
    	$args = array(
    		'label'               => __( 'projets', 'sim' ),
    		'description'         => __( 'Liste des projets', 'sim' ),
    		'labels'              => $labels,
    		'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'post-formats', ),
    		'taxonomies'          => array( 'category', 'post_tag' ),
    		'hierarchical'        => false,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 5,
    		//'menu_icon'           => '',
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'rewrite'			  => $rewrite,
    		'capability_type'     => 'post',
    	);
    
    	register_post_type( 'sim_projet', $args );
    }
    
    // Hook into the 'init' action
    add_action( 'init', 'sim_projets_post_type', 0 );

    and here is my loop :

    <?php
    	if ( get_query_var('paged') ) {
    		$paged = get_query_var('paged');
    	} elseif ( get_query_var('page') ) {
    		$paged = get_query_var('page');
    	} else {
    		$paged = 1;
    	}
    	?>
    
    	<?php query_posts(array("post_type" => "sim_projet", "posts_per_page" => 5, "cat" => get_query_var('cat'), "paged" => $paged)); ?>
    
    	<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	<div id="post-<?php the_ID();?>" class="category">
    		<div class="post-content">
    			<div class="entry-thumbnail">
    				<a href="<?php the_permalink() ; ?>">
    				<?php the_post_thumbnail(array(80,80)); ?>
    				</a>
    			</div>
    
    			<div class="entry-misc">
    				<h3 class="entry-title">
    					<a href="<?php the_permalink() ; ?>">
    					<?php the_title(); ?></a>
    				</h3>
    
    				<div class="entry-excerpt">
    					<?php the_excerpt();?>
    				</div>
    			</div>
    
    			<div class="clear"></div>
    		</div>
    
    	</div>
    	<?php endwhile; // end of the loop. ?>
    
    	<div class="clear"></div>

    anyone knows what could be the reason it is not displaying page n°2 ?

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic