您粘贴的代码并不一定是错误的,但是您所要求的也可以使用\'rewrite\' => true
http://codex.wordpress.org 国家:
has_archive
(布尔值或字符串)(可选)启用post类型存档。默认情况下,将使用$post\\U type作为归档段塞。
默认值:false
Note: Will generate the proper rewrite rules if rewrite is enabled. Also use rewrite to > change the slug used.
您的问题的解决方案可能是自定义帖子类型的模板不起作用或尚未创建,您可以尝试向函数中添加以下代码。php或插件功能:
function _post_type_template_smart(){
global $post;
$single_template_name = \'single-projects.php\';
$archive_template_name = \'archive-projects.php\';
if ( is_single() && \'projects\' == get_post_type() ){
$template = locate_template(array($single_template_name), true);
if(empty($template)) {
include(PLUGIN_DIR . \'template/\' . $single_template_name);
exit();
}
}else if( is_archive() && \'projects\' == get_post_type() ){
$template = locate_template(array($archive_template_name), true);
if(empty($template)) {
include(PLUGIN_DIR . \'template/\' . $archive_template_name);
exit();
}
}
}
add_filter(\'template_redirect\', \'_post_type_template_smart\');
在你的“单个项目”中。php“/”存档项目。php的页面,创建循环/查询/get\\u页面(以您喜欢的为准),以引入和显示内容:
$args = array(
//\'child_of\' => 0,
\'sort_order\' => \'ASC\',
\'sort_column\' => \'post_modified\',
\'hierarchical\' => 1,
\'parent\' => 0,
\'post_type\' => \'projects\',
\'post_status\' => \'publish\'
);
$pages = get_pages( $args );
foreach ( $pages as $project ){
$project_id = $project->ID;
$project_link = get_page_link($project->ID);
$project_title = $project->post_title;
$content = $project->post_content;
$author = $project->post_author;
$posted_on = $project->post_date;
if(empty($content)){
$content = \'There is no description for this package\';
}
echo \'<div class="content">\';
echo $content;
echo \'</div>\';
}
希望这有帮助!