正在查看 1 个帖子:1-1 (共 1 个帖子)
-
作者帖子
-
依旧是为了方便,薇晓朵博客的目的是让用户投稿,所以我们这里添加下已经投稿的文章数量统计
效果如下:
function author_post_count_shortcode( $atts ) { $atts = shortcode_atts( array( 'author' => '', ), $atts ); if ( ! empty( $atts['author'] ) ) { $author_id = $atts['author']; } else { $author_id = get_the_author_meta( 'ID' ); } $args = array( 'author' => $author_id, 'post_type' => 'post', 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => -1, ); $query = new WP_Query( $args ); $count = $query->found_posts; return $count; } add_shortcode( 'author_post_count', 'author_post_count_shortcode' );
使用方法:在文章或页面中,使用 [author_post_count] 简码调用即可显示当前文章作者的全部文章数量。可以使用 author 属性来指定特定的作者,例如 [author_post_count author=”2″] 将显示 ID 为 2 的作者的文章数量。
-
作者帖子
正在查看 1 个帖子:1-1 (共 1 个帖子)
- 哎呀,回复话题必需登录。