I am working on a theme with custom post type.
the issue currently is that i am saving the layout files in a folder called templates.. and in front-page.php i am using an options check to see which type of layout did the user selected from theme panel.. and include that file..
Right now in the custom post type template, pagination isn't working.. i am using this loop :
global $wp_query;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=portfolio&paged='.$paged);
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
......
<?php endwhile; endif; ?>
..
<?php
if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);}
?>
<?php $wp_query = null; $wp_query = $temp;?>
The pagination shows up but shows link as /page/2/ .. which gives 404 on running.. in my opinion it is showing the main query's page 2, as not many posts added so giving 404.
I have also tried :
$paged = 1;
if ( get_query_var('paged') ) $paged = get_query_var('paged');
if ( get_query_var('page') ) $paged = get_query_var('page');
Didn't work..
My Custom Post Register Structure :
function my_custom_post_portfolio() {
$labels = array(
'name' => _x( 'Portfolio', 'post type general name' ),
'singular_name' => _x( 'Portfolio', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Item' ),
'edit_item' => __( 'Edit Item' ),
'new_item' => __( 'New Portfolio Item' ),
'all_items' => __( 'All Items' ),
'view_item' => __( 'View Items' ),
'search_items' => __( 'Search Portfolio' ),
'not_found' => __( 'No Portfolio found' ),
'not_found_in_trash' => __( 'No Portfolio found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Portfolio'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our Portfolio and product specific data',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'portfolio', 'with_front' => true ),
'_builtin' => false, // It's a custom post type, not built in!
'query_var' => true,
'taxonomies' => array('portfolio', 'post_tag') // this is IMPORTANT
);
register_post_type( 'Portfolio', $args );
}
add_action( 'init', 'my_custom_post_portfolio' );
Help is appreciated! Thanks :)
pre_get_posts
– Milo May 10 '13 at 19:52