我最近需要在一个主题中解决一个非常类似的问题。代码的基础是post 我修改了一些代码
下面是我修改的代码的第一部分。
add_action(\'init\', \'limited_post_type\');
function my_custom_limited_post_type()
{
$labels = array(
\'name\' => _x(\'Limited Post Type\', \'post type general name\'),
\'singular_name\' => _x(\'Film - DVD\', \'post type singular name\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\', \'page-attributes\',\'custom-fields\' ),
\'show_in_nav_menus\' => true
);
register_post_type(\'limited_post_type\', $args);
}
下面是我修改过的代码的第二部分。
foreach ( $scope as $scopeItem ) {
switch ( $scopeItem ) {
case "post": {
// Output on any post screen
if ( basename( $_SERVER[\'SCRIPT_FILENAME\'] )=="post-new.php" || $post->post_type=="post" )
$output = true;
break;}
case "page": {
// Output on any page screen
if ( basename( $_SERVER[\'SCRIPT_FILENAME\'] )=="page-new.php" || $post->post_type=="page" )
$output = true;
break;}
case "limited_post_type": {
// Output on limited post_type onlye
if ((basename( $_SERVER[\'SCRIPT_FILENAME\'] )=="post-new.php" && $post->post_type=="limited_post_type" ) || (basename( $_SERVER[\'SCRIPT_FILENAME\'] )=="post.php" && $post->post_type=="film_dvd" ))
$output = true;
break;
}
如果你愿意,请给我发个信息,我会很高兴地把我的功能发给你。php文件供您参考。这绝对是实现这一目标的方法,因为我像你一样经历了许多个夜晚的拉扯。