在对自定义帖子类型进行了大量搜索和教育之后,我找到了答案。我还添加了一些东西,使规范更加细化。
// Add custom post type Artists
function register_artists_post_type() {
register_post_type(\'artists\',array(
\'labels\' => array(
\'name\' => __( \'Artists\' ),
\'singular_name\' => __( \'Artist\' ),
\'add_new\' => __( \'Add Artist\',\'Artist\' ),
\'add_new_item\' => __( \'Add New Artist\' ),
\'edit_item\' => __( \'Edit Artist\' ),
\'new_item\' => __( \'New Artist\' ),
\'view_item\' => __( \'View Artist\' ),
\'search_items\' => __( \'Search Artists\' ),
\'not_found\' => __( \'No Artists Found\' ),
\'not_found_in_trash\' => __( \'No Artists In Trash\' ),
\'parent_item_colon\' => \'\'
),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'has_archive\' => true,
\'supports\' => array( \'title\',\'editor\',\'excerpt\',\'custom-fields\',\'thumbnail\' ),
\'rewrite\' => array(\'slug\' => \'artists\'),
\'taxonomies\' => array(\'large_feature\',\'small_feature\'),
\'capability_type\' => \'post\',
\'hierarchical\' => false,
));
}
add_action(\'init\',\'register_artists_post_type\')
注册自定义分类法(对于新手来说,这是一种说类别的奇特方式……“类别”在普通帖子中只是默认的分类法)
// Add custom taxonomies for Artists post type
add_action(\'init\',\'register_large_feature_taxonomy\');
function register_large_feature_taxonomy() {
register_taxonomy(\'large_feature\',array(\'artists\'),array(
\'hierarchical\' => true,
\'label\' => \'Large Feature\',
\'public\'=> true,
\'show_ui\'=> true,
\'query_var\'=> true,
\'rewrite\' => false,
));
}
add_action(\'init\',\'register_small_feature_taxonomy\');
function register_small_feature_taxonomy() {
register_taxonomy(\'small_feature\',array(\'artists\'),array(
\'hierarchical\' => true,
\'label\' => \'Small Feature\',
\'public\'=> true,
\'show_ui\'=> true,
\'query_var\'=> true,
\'rewrite\' => false,
));
}
最后,查询,如
archive-artists.php
<?php query_posts(array(
\'large_feature\' => \'artists_page_large\', // this is the same as calling for a category within standard posts, where \'large_feature\' is category and \'artists_page_large\' is the ID/slug (either should work, I chose to use the slug to avoid going back to check ID numbers)
\'showposts\' => 1,
\'orderby\' => \'rand\', // randomizes the posts each page load
));
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div id="post-<?php the_ID(); ?>" class="artistSingle white">
<!-- do stuff -->
</div>
<?php endwhile; endif; // end of featured large loop ?>
<div id="featArtistSm" class="white">
<?php rewind_posts(); // start featured small loop ?> <!-- rewind allows for multiple loops on a single page -->
<?php query_posts(array(
\'small_feature\' => \'artists_page_small\',
\'showposts\' => 4,
\'orderby\' => \'rand\',
));
?>
<?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
<div class="featArtistSmSng white">
<-- do stuff -->
</div>
<?php endwhile; endif; // end of featured small loop ?>
</div>
<div id="featuredArtists">
<div id="artistRoster" class="artistRoster">
// query to pull all posts of \'artist\' custom post type
<?php query_posts(\'post_type=artists&orderby=title&order=asc&posts_per_page=-1\'); ?>
<?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
<p class="roster"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; endif; ?>
</div>
</div>
希望这对其他人有所帮助!因为我最初有一个类别叫做“带鼻涕虫的艺术家”
artists
, 我最终删除了所有类别,并将slug用于自定义帖子类型。它更干净,消除了混淆系统的可能性。原来我还有一个名为“艺术家”的页面,其中有一个模板页面被我删除了,但该页面仍然是垃圾。确保从垃圾箱中删除任何冲突的项目!即使它在垃圾桶中,它仍然在你的数据库中。