WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP Paginate doesn't work in my Custom Post Type Archive Page (5 posts)

  1. Enea Dhiamandi
    Member
    Posted 1 year ago #

    I have a problem with the WP Paginate to a theme I recently developed, it seems I can't make the plugin show up in the custom post type archive page.

    The plugin works perfectly fine in the category, search, archive template but it doesn't show up in the custom post type I made.

    I have shorten the code so if you want to see the entire files download the zip here: http://www.sendspace.com/file/crfoea
    Any help would be appreciated. Thanks!

    My template:

    <?php
     /*
    Template Name: Consumables Page
     */
    ?>
    
    <?php get_header(); ?>
    
    <div id="container">
    <div class="container">
    <?php
    $args = array( 'post_type' => 'consumables' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    <div class="product">
    
    ----- bla bla bla -----
    
    </div>
    <?php endwhile; ?>
    <nav>
    <?php if(function_exists('wp_paginate')) {
    wp_paginate();
    } ?>
    </nav>
    </div>
    </div>
    </div>
    
    <?php get_footer(); ?>

    The functions temp:

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    register_post_type( 'consumables',
    	array(
    	'labels' => array(
    	'name' => __( 'Consumables' ),
    	'singular_name' => __( 'Consumable' )
    	),
    	'public' => true,
    	'hierarchical' => true,
    	'supports' => array( 'title', 'editor', 'thumbnail')
    	)
    	);
    }
    
    $labels = array(
    	    'name'                          => 'Labeling',
    	    'singular_name'                 => 'Label',
    	    'search_items'                  => 'Search Labeling',
    	    'popular_items'                 => 'Popular Labeling',
    	    'all_items'                     => 'All Labeling',
    	    'parent_item'                   => 'Parent Labeling',
    	    'edit_item'                     => 'Edit Labeling',
    	    'update_item'                   => 'Update Labeling',
    	    'add_new_item'                  => 'Add New Labeling',
    	    'new_item_name'                 => 'New Labeling',
    	    'separate_items_with_commas'    => 'Separate Labeling with commas',
    	    'add_or_remove_items'           => 'Add or remove Labeling',
    	    'choose_from_most_used'         => 'Choose from most used Labeling'
    	    );
  2. Scott Fennell
    Member
    Posted 1 year ago #

    I *think* what you need to do, is make sure you declare has_archive as TRUE when you create the post type:

    http://codex.wordpress.org/Function_Reference/register_post_type

    And then, don't use a custom page template with a custom query like you are doing. Instead, use a archives-your-post-type-name-here.php page template, and just navigate directly to that page, however that may be, depending on your permalink structure and the name of the post type.

    Edit to add: You will have to add a pagination function of your choice to that archives template.

    http://codex.wordpress.org/Next_and_Previous_Links

    At that point, it should paginate just like any archives page.

  3. Enea Dhiamandi
    Member
    Posted 1 year ago #

    I added this in functions.php :

    register_post_type( 'consumables',
    			array(
    				'labels' => array(
    					'name' => __( 'Consumables' ),
    					'singular_name' => __( 'Consumable' )
    				),
    				    'public' => true,
    				    'publicly_queryable' => true,
    				    'show_ui' => true,
    				    'show_in_menu' => true,
    				    'query_var' => true,
    				    'rewrite' => true,
    				    'capability_type' => 'post',
    				    'has_archive' => true,
    				    'hierarchical' => false,
    				    'menu_position' => null,
    				'supports' => array( 'title', 'editor', 'thumbnail')
    			)
    		);

    And created the archive-consumables.php template as you said but I can't find the way to see the result of the template.. what url should a post type archive generate with %Postname% permalinks set in the wordpress options?

    I have tried adding archive templates before but I needed a easy way for my client to access and add the archives in the navigation without much frustration, so I enabled categories in the custom post type to make it easier to add in custom menu and it messed my custom tags for good.. that's why i chose Page Template!

    Thanks for your effort man,
    i appreciate it!

  4. Scott Fennell
    Member
    Posted 1 year ago #

    You should be able to get to the archive via http://www.yoursite.com/consumables. Make sure you flush your rewrite cache by changing and then re-changing your permalinks. That's a common pitfall on stuff like this.

    Also, I'm not sure but if you manually entered %Postname% as your permalink structure, you might have screwed up by capitalizing it. All lowercase is the sure bet.

  5. Enea Dhiamandi
    Member
    Posted 1 year ago #

    I did what you said man and it worked.. changed the temp to archive and re-changed my permalinks and everything worked like a charm.. fixed the pagination and several bugs I couldn't fix.. thanks alot man!

Topic Closed

This topic has been closed to new replies.

About this Topic