我设置了多种自定义帖子类型。我在许多网站上多次经历过这个过程,从来没有遇到过问题。
帖子类型注册为“glossary”。存档是“存档词汇表”。php’。“单一”是“单一词汇表”。php’。
在我的归档页面上,我基本上有以下内容:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
等等。。。
如果您单击其中一个通常会将您带到单个词汇表的链接。php它只是重新加载归档词汇表。php。
在同一个网站上,我有许多帖子类型都是以完全相同的方式设置的。我刚刚开始制作一个页面模板,所以它们都非常通用。我已经刷新了永久链接,删除并重新注册了帖子类型,更改了主题,检查并再次检查了拼写错误,完全清除了浏览器缓存,使用了4种不同的浏览器,只是看不到任何可能导致这种情况的原因。
我希望有人能提供一些明智的故障排除建议。
根据要求,我使用以下内容创建自定义帖子类型:
class CustomPostType{
protected $textdomain;
protected $posts;
public function __construct($textdomain){
$this->textdomain = $textdomain;
$this->posts = array();
add_action(\'init\', array(&$this, \'register_custom_post\'));
}
public function make($type, $properLabel, $singularLabel, $pluralLabel, $icon, $slug, $settings = array()){
if(isset($singularLabel)){$singluarLabel = $singularLabel;}else{$singularLabel = \'\';}
if(isset($pluralLabel)){$pluralLabel = $pluralLabel;}else{$pluralLabel = \'\';}
$default_settings = array(
\'labels\' => array(
//Title Of the Group
\'name\' => __($properLabel, $this->textdomain),
//Individual Type
\'singular_name\' => __($singluarLabel, $this->textdomain),
// "All %Items%" Menu Item
\'all_items\' => __( \'All \'.$pluralLabel, $this->textdomain),
//The "Add New" Menu Item
\'add_new\' => __( \'Add New \'.$singularLabel, $this->textdomain ),
//Add New Display Title
\'add_new_item\' => __(\'Add New \'.$singularLabel, $this->textdomain),
//Edit Dialog
\'edit\' => __( \'Edit\', $this->textdomain), /* Edit Dialog */
//Edit Display Title
\'edit_item\' => __(\'Edit \'.$pluralLabel, $this->textdomain),
//New Display Title
\'new_item\' => __(\'New \'.$singularLabel, $this->textdomain),
//View Display Title
\'view_item\' => __(\'View \'.$singularLabel, $this->textdomain),
//Search Custom Type Title
\'search_items\' => __(\'Search \'.$pluralLabel, $this->textdomain),
//Displays if No Entry Found
\'not_found\' => __(\'No \'.$pluralLabel.\' found.\', $this->textdomain),
//Not found in Trash
\'not_found_in_trash\' => __(\'No \'.$pluralLabel.\' found in trash.\', $this->textdomain),
//Only in Hierarchical Post Types "Parent %Item%"
\'parent_item_colon\' => __(\'Parent \'.$singluarLabel, $this->textdomain),
),
//Custom Type Description
\'description\' => __( \'This is the \'.$properLabel.\' custom post type\', $this->textdomain), /* Custom Type Description */
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_position\' => 20,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/library/images/admin-panel/\'.$icon.\'-icon.png\',
\'rewrite\' => array(
\'slug\' => $slug
),
\'has_archive\' => sanitize_title_with_dashes($slug),
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'supports\' => array(
\'title\',
\'editor\',
\'author\',
\'thumbnail\',
\'excerpt\',
\'custom-fields\',
\'revisions\',
\'sticky\',
\'page-attributes\'
),
);
$this->posts[$type] = array_merge($default_settings, $settings);
}
public function register_custom_post(){
foreach($this->posts as $key=>$value) {
register_post_type($key, $value);
}
}
}//End Class
$type_glossary = new CustomPostType(\'thetextdomain\');
$type_glossary->make(\'glossary\', \'Glossary\', \'Term\', \'Terms\', \'glossary\', \'glossary\');