1
votes

I am trying to create single page for custom post types but i can't really achieve it. Here is all that i am trying out -

snippet from functions.php for the registration of the custom post type

<?php
function custom_post_type() {

$labels = array(
    'name'                => _x( 'Tutorials', 'Post Type General Name', 'text_domain' ),
    'singular_name'       => _x( 'Tutorial', 'Post Type Singular Name', 'text_domain' ),
    'menu_name'           => __( 'Tutorial', 'text_domain' ),
    'parent_item_colon'   => __( 'Parent Tutorial:', 'text_domain' ),
    'all_items'           => __( 'All Tutorials', 'text_domain' ),
    'view_item'           => __( 'View Tutorial', 'text_domain' ),
    'add_new_item'        => __( 'Add New Tutorial', 'text_domain' ),
    'add_new'             => __( 'New Tutorial', 'text_domain' ),
    'edit_item'           => __( 'Edit Tutorial', 'text_domain' ),
    'update_item'         => __( 'Update Tutorial', 'text_domain' ),
    'search_items'        => __( 'Search Tutorials', 'text_domain' ),
    'not_found'           => __( 'No Tutorials found', 'text_domain' ),
    'not_found_in_trash'  => __( 'No Tutorials found in Trash', 'text_domain' ),
);
$args = array(
    'label'               => __( 'Tutorial', 'text_domain' ),
    'description'         => __( 'Tutorial information pages', 'text_domain' ),
    'labels'              => $labels,
    'supports'            => array('title','editor','author','excerpt','custom-fields'),
    '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,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);
register_post_type( 'Tutorial', $args );
}
add_action( 'init', 'custom_post_type' ); ?>

and i am using the template named single-Tutorial.php for this custom post type template. Also, in my posts display i am using the_permalink() to link to the post.

Now consider a post with title test3 now in my dashboard i see its permalink as -

http://localhost/deadman/portfolio/tutorial/test3/

and when i echo the contents of the_permalink i get -

http://localhost/deadman/portfolio/tutorial/test3/ 

Now though they are pointing at the same place but still i am being redirected to the homepage rather than the single post type page

1
The name of custom post can't contains capital letters as the codex says : codex.wordpress.org/Function_Reference/register_post_type. Try to change the name to tutorial and not Tutorial. Maybe that will help. Also the template file should be single-tutorial.phpLaxmana
Okay i tried tutorial too, and renamed my filename to - single-tutorial.php but no luck, anyway i just have some dummy content in my single-tutorial.php for testing purpose and is this in any way related to this problemHarshit Laddha
Did you also change 'register_post_type( 'Tutorial', $args );' to 'register_post_type( 'tutorial', $args );' ?Laxmana
Yes i replaced every instance of Tutorial to tutorial in my functions.php and also tried changing the capability_type to => 'post'Harshit Laddha
Xmm strange. Normally when I have this kind of problems I go to Setting->Permantlink and save again. It is needed it to flush the new url's.Laxmana

1 Answers

1
votes

The name of custom post can't contains capital letters so change the register_post_type( 'Tutorial', $args ); to register_post_type( 'tutorial', $args );

Also the template file should be single-tutorial.php and not single-Tutorial.php.

Lastly you have to save the permalink settings to flush the news url's. That is need it because wordpress cache the rewrite rules and when you create a custom post wordpress don't automatically refresh the new rewrite rules.

Usefull links :

http://wp-bytes.com/function/2013/02/flushing-permalinks/

http://codex.wordpress.org/Rewrite_API/flush_rules