我的英语不是很好看
在我的功能中,我有几种自定义的帖子类型,“noticias”(新闻)、“articulos”(文章)等。php i使用如下代码按post\\u id或post\\u类型将脚本和样式排队:
function mahg_scripts_by_page() {
global $post;
$page_id = $post->ID;
$post_type = $post->post_type; // var_dump($post_type);
$noti = \'noticia\'; // POST-TYPE noticia
$arti = \'articulo\'; // POST-TYPE articulo
$com1 = 4; // that page id
$com2 = 6; // that other page id
// $etc if i needed
$front_commons = array($noti, $arti, $com1, $com2, $etc);
if ( is_home() || is_404() || is_single() || in_array($page_id, $front_commons, true) ) {
wp_register_style(\'uikit_css\', get_template_directory_uri().\'/css/uikit.css\', array(), \'\', \'all\' );
wp_enqueue_style(\'uikit_css\');
wp_register_script(\'uikit_js\', get_template_directory_uri().\'/js/uikit.min.js\',\'\',\'\', true );
wp_enqueue_script(\'uikit_js\');
if (is_home() ) {
wp_register_style(\'slideshow_css\', get_template_directory_uri().\'/css/components/slideshow.css\', array(), \'\', \'all\' );
wp_enqueue_style(\'slideshow_css\');
wp_register_script(\'slideshow_js\', get_template_directory_uri().\'/js/components/slideshow.min.js\',\'\',\'\', true );
wp_enqueue_script(\'slideshow_js\');
}
// more scripts or styles from here
}
add_action(\'wp_enqueue_scripts\', \'mahg_scripts_by_page\' );
我创建了
archive-noticia.php
和
archive-articulo.php
在我的主题文件夹中。但当运行网站时,浏览器会在articulo archive页面中加载脚本和样式,但在Notifia archive页面中不会加载脚本和样式
var_dump($post_type);
显示
\'articulo\' (length=8)
在articulo archive页面中。但是显示
null
在Notifia archive页和其他自定义帖子类型中<当我做
register_post_type( \'articulo\', $args);
, has\\u archive设置为true。noticia也一样。
$singular = \'Artículo\';
$plural = \'Artículos\';
$labels = array(
\'name\' => $plural,
\'singular_name\' => $singular,
\'add_new\' => \'Nuevo \' . $singular,
\'add_new_item\' => \'Agregar nuevo \' . $singular,
\'edit\' => \'Editar\',
\'edit_item\' => \'Editar \' . $singular,
\'new_item\' => \'Nuevo \' . $singular,
\'view\' => \'Ver \' . $singular,
\'view_item\' => \'Ver \' . $singular,
\'search_term\' => \'Buscar \' . $plural,
\'parent\' => \'Parent \' . $singular,
\'not_found\' => \'No se han encontrado \' . $plural,
\'not_found_in_trash\' => \'No hay \' . $plural .\' en la papelera\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'show_in_nav_menus\' => false,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_admin_bar\' => false,
\'menu_position\' => 7,
\'menu_icon\' => \'dashicons-media-spreadsheet\',
\'can_export\' => true,
\'delete_with_user\' => false,
\'hierarchical\' => true,
\'has_archive\' => true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'map_meta_cap\' => true,
\'rewrite\' => true,
\'rewrite\' => array(
\'slug\' => \'articulos\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => false,
),
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'excerpt\')
);
register_post_type( \'articulo\', $args);
$singular = \'Noticia\';
$plural = \'Noticias\';
$labels = array(
\'name\' => $plural,
\'singular_name\' => $singular,
\'add_new\' => \'Nueva \' . $singular,
\'add_new_item\' => \'Agregar nueva \' . $singular,
\'edit\' => \'Editar\',
\'edit_item\' => \'Editar \' . $singular,
\'new_item\' => \'Nueva \' . $singular,
\'view\' => \'Ver \' . $singular,
\'view_item\' => \'Ver \' . $singular,
\'search_term\' => \'Buscar \' . $plural,
\'parent\' => \'Parent \' . $singular,
\'not_found\' => \'No se han encontrado \' . $plural,
\'not_found_in_trash\' => \'No hay \' . $plural .\' en la papelera\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => false,
\'show_in_menu\' => true,
\'show_in_admin_bar\' => false,
\'menu_position\' => 6,
\'menu_icon\' => \'dashicons-media-document\',
\'capability_type\' => \'post\',
\'map_meta_cap\' => true,
\'hierarchical\' => true,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'excerpt\'),
\'has_archive\' => true,
\'rewrite\' => true,
\'rewrite\' => array(
\'slug\' => \'noticias\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => false,
),
\'query_var\' => true,
\'can_export\' => true,
\'delete_with_user\' => false,
);
register_post_type( \'noticia\', $args);
wordpress为什么这么做?我做错了什么?