[英]wordpress single custom post type template
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 来自functions.php的摘录,用于自定义帖子类型的注册
<?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. 我正在使用名为single-Tutorial.php的模板作为此自定义帖子类型模板。 Also, in my posts display i am using the_permalink() to link to the post.
另外,在我的帖子显示中,我正在使用the_permalink()链接到该帖子。
Now consider a post with title test3 now in my dashboard i see its permalink as - 现在考虑在我的信息中心中标题为test3的帖子,我将其永久链接视为-
http://localhost/deadman/portfolio/tutorial/test3/
and when i echo the contents of the_permalink i get - 当我回显the_permalink的内容时,我得到-
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 现在,尽管他们都指向同一个地方,但我仍被重定向到主页,而不是单个帖子类型页面
The name of custom post can't contains capital letters so change the register_post_type( 'Tutorial', $args );
自定义帖子的名称不能包含大写字母,因此请更改
register_post_type( 'Tutorial', $args );
to register_post_type( 'tutorial', $args );
到
register_post_type( 'tutorial', $args );
Also the template file should be single-tutorial.php
and not single-Tutorial.php
. 模板文件也应该是
single-tutorial.php
而不是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.
这是必需的,因为wordpress会缓存重写规则,并且当您创建自定义post wordpress时不会自动刷新新的重写规则。
Usefull links : 有用的链接:
http://wp-bytes.com/function/2013/02/flushing-permalinks/ http://wp-bytes.com/function/2013/02/flushing-permalinks/
http://codex.wordpress.org/Rewrite_API/flush_rules http://codex.wordpress.org/Rewrite_API/flush_rules
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.