| 1 |
<?php |
| 2 |
|
| 3 |
wp_enqueue_style('betterdocs-pagination'); |
| 4 |
|
| 5 |
$author_id = get_query_var( 'author' ); |
| 6 |
$page = get_query_var( 'page' ); |
| 7 |
$enable_pagination = false; |
| 8 |
|
| 9 |
$default_args = [ |
| 10 |
'post_type' => 'docs', |
| 11 |
'author' => $author_id, |
| 12 |
'posts_per_page' => -1 |
| 13 |
]; |
| 14 |
|
| 15 |
if ( ! empty( $page ) ) { // if page is found enable pagination |
| 16 |
$default_args['paged'] = $page; |
| 17 |
$default_args['posts_per_page'] = 10; |
| 18 |
$enable_pagination = true; |
| 19 |
} |
| 20 |
|
| 21 |
$post_query = new WP_Query( $default_args ); |
| 22 |
|
| 23 |
$author_docs_count = count_user_posts( $author_id, 'docs' ); |
| 24 |
$author_name = get_the_author_meta( 'nicename', $author_id ); |
| 25 |
$author_avatar_tag = get_avatar( $author_id, 40 ); |
| 26 |
|
| 27 |
|
| 28 |
get_header(); |
| 29 |
|
| 30 |
?> |
| 31 |
<div class="betterdocs-wrapper betterdocs-taxonomy-wrapper betterdocs-archive-layout-7 betterdocs-category-archive-wrapper betterdocs-wraper"> |
| 32 |
<div class="betterdocs-content-wrapper betterdocs-display-flex doc-category-layout-7"> |
| 33 |
<div id="main" class="betterdocs-content-area"> |
| 34 |
<div class="betterdocs-content-inner-area"> |
| 35 |
<?php |
| 36 |
|
| 37 |
betterdocs()->views->get( 'template-parts/author-header', [ |
| 38 |
'author_name' => $author_name, |
| 39 |
'author_docs_count' => $author_docs_count, |
| 40 |
'avatar_tag' => $author_avatar_tag |
| 41 |
] ); |
| 42 |
|
| 43 |
betterdocs()->views->get( 'template-parts/author-archive-doc-list', [ |
| 44 |
'post_query' => $post_query |
| 45 |
] ); |
| 46 |
|
| 47 |
if ( $enable_pagination ) { |
| 48 |
global $wp; |
| 49 |
$remove_the_last_two_vars = explode( '/', $wp->request ); |
| 50 |
$new_link = home_url() .'/'. implode( '/', array_slice( $remove_the_last_two_vars, 0, ( count( $remove_the_last_two_vars ) - 2 ) ) ) . '/'; |
| 51 |
$total_pages = ceil( ( isset( $post_query->found_posts ) ? $post_query->found_posts : 0 ) / 10 ); |
| 52 |
|
| 53 |
betterdocs()->views->get( |
| 54 |
'template-parts/pagination', |
| 55 |
[ |
| 56 |
'total_pages' => $total_pages, |
| 57 |
'link' => $new_link, |
| 58 |
'current_page' => isset( $page ) ? $page : 1, |
| 59 |
'template' => 'doc_category' //bypass the template to be used in authors template |
| 60 |
] |
| 61 |
); |
| 62 |
} |
| 63 |
?> |
| 64 |
</div> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
</div> |
| 68 |
|
| 69 |
<?php |
| 70 |
get_footer(); |
| 71 |
?> |
| 72 |
|