213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 more
ThemeChills
says

Thanks for helping with this @Smartik

I’m new to custom post types, hence all the confusion.

I can see that the post type is registered, though my arguments for them are currently set as follows… which argument should I update?


function chills_photo_gallery_init() {

    // Photos custom post type
    $labels = array(
        'name'               => _x( 'Photos', 'chills' ),
        'singular_name'      => _x( 'Photo', 'chills' ),
        'add_new_item'       => __( 'Add New Photo', 'chills' ),
        'edit_item'          => __( 'Edit Photo', 'chills' ),
        'new_item'           => __( 'New Photo', 'chills' ),
        'all_items'          => __( 'All Photos', 'chills' ),
        'view_item'          => __( 'View Photo', 'chills' ),
        'search_items'       => __( 'Search Photos', 'chills' ),
        'not_found'          => __( 'No slides found', 'chills' ),
        'not_found_in_trash' => __( 'No slides found in the Trash', 'chills' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Photos'
    );

    $args = array(
        'labels'              => $labels,
        'public'             => false,  
        'show_ui'              => true,  
        'capability_type'      => 'post',
        'rewrite'              => array("slug" => "photo"),  
        'hierarchical'         => false,  
        'rewrite'              => true,  
        'supports'             => array('title', 'editor', 'thumbnail')  
    );

    register_post_type('photo', $args );
}

I also used the code that you revised and it is showing the title for my custom post type, though the pagination does not exist…

Thanks again, really appreciate it.

Leo

1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+5 more
Smartik
says
As you can see your post type is not public. 'public' => false,. Here is the full code. Remember to update permalink setting after replacing the code.
function chills_photo_gallery_init() {

    // Photos custom post type
    $labels = array(
        'name'               => _x( 'Photos', 'chills' ),
        'singular_name'      => _x( 'Photo', 'chills' ),
        'add_new_item'       => __( 'Add New Photo', 'chills' ),
        'edit_item'          => __( 'Edit Photo', 'chills' ),
        'new_item'           => __( 'New Photo', 'chills' ),
        'all_items'          => __( 'All Photos', 'chills' ),
        'view_item'          => __( 'View Photo', 'chills' ),
        'search_items'       => __( 'Search Photos', 'chills' ),
        'not_found'          => __( 'No slides found', 'chills' ),
        'not_found_in_trash' => __( 'No slides found in the Trash', 'chills' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Photos'
    );

    $args = array(
        'labels'              => $labels,
        'public'             => true, 
        'has_archive'        => true,
        'publicly_queryable' => true, 
        'query_var'          => true, 
        'rewrite'            => array(
            'slug' => $post_type, // or something else
        ),
        'show_ui'              => true,  
        'capability_type'      => 'post',
        'rewrite'              => array("slug" => "photo"),  
        'hierarchical'         => false,  
        'supports'             => array('title', 'editor', 'thumbnail')  
    );

    register_post_type('photo', $args );
}
213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 more
ThemeChills
says

Yep, saw that just before receiving your reply.

UPDATED the code to the below:


function chills_photo_gallery_init() {

    // Photos custom post type
    $labels = array(
        'name'               => _x( 'Photos', 'post type general name', 'chills' ),
        'singular_name'      => _x( 'Photo', 'post type singular name', 'chills' ),
        'menu_name'          => _x( 'Photos', 'admin menu', 'chills' ),
        'name_admin_bar'     => _x( 'Photo', 'add new on admin bar', 'chills' ),
        'add_new'            => _x( 'Add New', 'photo', 'chills' ),
        'add_new_item'       => __( 'Add New Photo', 'chills' ),
        'new_item'           => __( 'New Photo', 'chills' ),
        'edit_item'          => __( 'Edit Photo', 'chills' ),
        'view_item'          => __( 'View Photo', 'chills' ),
        'all_items'          => __( 'All Photos', 'chills' ),
        'search_items'       => __( 'Search Photos', 'chills' ),
        'parent_item_colon'  => __( 'Parent Photos:', 'chills' ),
        'not_found'          => __( 'No photos found.', 'chills' ),
        'not_found_in_trash' => __( 'No photos found in Trash.', 'chills' )
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'photo' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'             => array('title', 'editor', 'thumbnail')
    );

    register_post_type('photo', $args );
}

Still have no pagination even after updating the permalink structure. Here is a demo link http://wp.themechills.com/sandbox/

The post types show, but the pagination does not.

Thoughts?

1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+5 more
Smartik
says

Thoughts?

How many posts do you have? It should be more than 8.

213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 more
ThemeChills
says

Now I managed to get the pagination working with the below code (added $photo_query->max_num_pages), though it goes to a 404. Because it is a one page theme, I essentially need for the records to paginate though stay on the same page.


  <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries', $photo_query->max_num_pages) ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
  </div>

213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 more
ThemeChills
says


Thoughts?
How many posts do you have? It should be more than 8.

I have 8 added, but changed the posts_per_page to 4 just to test if the pagination would show… I updated the permalink structure too.

Pagination works, but as I said in the last reply, goes to a 404…

1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+5 more
Smartik
says
I have no idea what could be the problem here. Try adding this on WP_Query: 'cat' => -0
$args  = array(
        'post_type'           => 'photo',
        'post_status'         => 'publish',
        'paged'               => $paged,
        'posts_per_page'      => 8,
        'cat'                 => -0
        'ignore_sticky_posts' => 1
);

$photo_query = new WP_Query( $args );
223 posts
  • Affiliate Level 1
  • Collector Level 3
  • 6 Years of Membership
  • Exclusive Author
agusmu
says

Pagination works, but as I said in the last reply, goes to a 404…

where do you put this code? what file?

186 posts
  • Power Elite Author
  • 6 Years of Membership
  • Author Level 12
  • Trendsetter
+7 more
stmcan
says



Thoughts?
How many posts do you have? It should be more than 8.

I have 8 added, but changed the posts_per_page to 4 just to test if the pagination would show… I updated the permalink structure too.

Pagination works, but as I said in the last reply, goes to a 404…

Does it work, when you reduce the “Blog pages show at most” number to 8 or smaller number? (via Settings -> Reading Settings )

If so, you can add an action to “pre_get_posts” http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

Something like;

function tax_pagination_fix($query) {  
    $post_per_page = 8 ; 
    $query->set('posts_per_page',  $post_per_page );
    return $query;  
}
add_filter('pre_get_posts','tax_pagination_fix');

Hope it helps!

Tolga

DistinctiveThemes
DistinctiveThemes Recent Posts Threads Started
323 posts
  • Trendsetter
  • Exclusive Author
  • Author Level 6
  • 2 Years of Membership
+4 more
DistinctiveThemes
says

The quality of advice in this post is pure gold

What a brilliant community we have here :)

by
by
by
by
by
by