我为我也创建的自定义帖子类型创建了一个自定义存档页面。我只想设置此自定义存档页面的样式。我试图在 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);
最佳答案
如果我没有正确理解问题,那么您已经为您的自定义帖子类型存档创建了一个模板。
如果您查看的页面已分配有文件名为“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
关于php - 为自定义帖子类型添加自定义样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43459263/