一个分享WordPress、Zblog、Emlog、Typecho等主流博客的教程网站!
当前位置:网站首页 > WordPress教程 > 正文

WordPress 作者存档页面显示自定义文章类型的内容

作者:xlnxin发布时间:2021-04-15分类:WordPress教程浏览:389


导读:WordPress默认会创建一个作者存档页面,例如...

WordPress 默认会创建一个作者存档页面,例如 https://www.wpdaxue.com/author/cmhello 会显示该作者发布的所有文章,但是如果你的网站使用了自定义文章类型,默认情况下,在这个存档页面是不显示该作者发布的自定义文章类型的内容的。如果你希望它显示,可以在主题的 functions.php 添加下面的代码:

123456789101112
/*** WordPress 作者存档页面显示自定义文章类型的内容* https://www.wpdaxue.com/custom-post-types-author-archives.html*/function post_types_author_archives($query) {// 添加 questions 这个自定义文章类型到作者存档if ( $query->is_author )$query->set( 'post_type', array('questions', 'post') );// 运行后移除这个挂载动作,防止无限执行remove_action( 'pre_get_posts', 'post_types_author_archives' );}add_action( 'pre_get_posts', 'post_types_author_archives' );

请根据自己的实际,修改第 8 行的文章类型。

标签:wordpresshtml主题