I've have tried to make my first wordpress theme and I have some trouble with my single pages for my blog. [my blog page][1]
It is a custom post type, that I created called blog_post. The weird this seems to happen only when it is on a sublayer of my site ex. {url}/blog_post/ here the page looks just like my index page.
But on my work page there isn't any problem with my single pages, and their permalink doesn't have a {url}/work_post/ attach to them. [my work page][2]
I created the special styling of my single pages with functions.php file
define(SINGLE_PATH, TEMPLATEPATH . '/single');
/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');
/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;
/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';
/* <-------- if no single-cat page is found the return the single.php file
*/
elseif(file_exists(SINGLE_PATH . '/single.php'))
return SINGLE_PATH . '/single.php';
endforeach;
}
I hope someone can make sense of my mess :D
I found the answer myself by simply removing the additions to functions.php and then making custom post for my work page as well.
then I make single-{slug}.php pages for every slug I wanted :D everybody is happy
You need to add "public => true" in your custom post type. Also create single-{custom-post-type}.php file
Code:
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'heirachical' => false,
'menu_position' => 26,
'has_archive' => true,
'menu_icon' => 'dashicons-products',
'supports' => array( 'title', 'editor','thumbnail' ),
'query_var' => true,
'capability_type' => 'post',
'rewrite' => true,
);
For example: Suppose you have created custom post type say "product" then you need to create single-product.php file in your theme directory.
Note: Save your permalink setting.
For me it worked to add 'publicly_queryable' => true
to the arguments of registering the post_type. I originally had to setting set to false
.