为自定义帖子类型添加自定义样式表

时间:2017-04-17 20:43:02

标签: php css wordpress

我为自己创建的自定义帖子类型创建了一个自定义存档页面。我想仅设置此自定义存档页面的样式。我试过在functions.php中创建一个函数,但它不起作用。

我的问题是:如何在此存档页面中使用自定义样式表而不在其他页面上使用?

由于

function interviewlist_style() {
if ( is_page_template('archive-interview.php') )
wp_enqueue_style('Archive Interviews', get_stylesheet_directory_uri() . '/css/archive_interviews.css');
}
add_action( 'wp_enqueue_scripts', 'interviewlist_style', 1);

1 个答案:

答案 0 :(得分:0)

如果我已正确理解该问题,您已为自定义帖子类型存档创建了模板。

如果您正在查看已分配了文件名为' archive-interview.php'的自定义模板的页面,那么您使用的条件将适用。当您处理存档而不是页面时,您需要使用不同的功能。

替换:

if ( is_page_template('archive-interview.php') )

使用:

if ( is_post_type_archive( 'interview' ) )

如果您正在查看名为'面试的自定义帖子类型的存档,则会评估为真。

https://codex.wordpress.org/Function_Reference/is_post_type_archive

相关问题