WordPress 默认会创建一个作者存档页面,例如 https://www.wpdaxue.com/author/cmhello 会显示该作者发布的所有文章,但是如果你的网站使用了自定义文章类型,默认情况下,在这个存档页面是不显示该作者发布的自定义文章类型的内容的。如果你希望它显示,可以在主题的 functions.php 添加下面的代码:
/**
* 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' ); |
/**
* 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 行的文章类型。
来源:
https://www.wpdaxue.com/custom-post-types-author-archives.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32724.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57