| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Editors\BlockEditor\Block; |
| 6 |
|
| 7 |
class ArchiveHeader extends Block { |
| 8 |
|
| 9 |
protected $editor_styles = [ 'betterdocs-category-archive-header' ]; |
| 10 |
|
| 11 |
protected $frontend_styles = [ 'betterdocs-category-archive-header', 'betterdocs-doc_category' ]; |
| 12 |
|
| 13 |
public function get_name() { |
| 14 |
return 'archive-header'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_default_attributes() { |
| 18 |
return [ |
| 19 |
'blockId' => '', |
| 20 |
'titleTag' => 'h2' |
| 21 |
]; |
| 22 |
} |
| 23 |
|
| 24 |
public function render( $attributes, $content ) { |
| 25 |
$this->views( 'widgets/archive-header' ); |
| 26 |
} |
| 27 |
|
| 28 |
public function view_params() { |
| 29 |
$current_category = get_queried_object(); |
| 30 |
|
| 31 |
$args = betterdocs()->query->docs_query_args( |
| 32 |
[ |
| 33 |
'term_id' => isset( $current_category->term_id ) ? $current_category->term_id : '', |
| 34 |
'term_slug' => isset( $current_category->slug ) ? $current_category->slug : '', |
| 35 |
'posts_per_page' => -1 |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
$post_query = new \WP_Query( $args ); |
| 40 |
|
| 41 |
$_nested_categories = betterdocs()->query->get_child_term_ids_by_parent_id( 'doc_category', ( isset( $current_category->term_id ) ? $current_category->term_id : '' ) ); |
| 42 |
|
| 43 |
if ( $_nested_categories ) { |
| 44 |
$sub_terms_count = count( explode( ',', $_nested_categories ) ); |
| 45 |
} else { |
| 46 |
$sub_terms_count = 0; |
| 47 |
} |
| 48 |
|
| 49 |
return [ |
| 50 |
'current_category' => $current_category, |
| 51 |
'found_posts' => $post_query->found_posts, |
| 52 |
'show_count' => true, |
| 53 |
'title_tag' => $this->attributes['titleTag'], |
| 54 |
'show_icon' => true, |
| 55 |
'sub_terms_count' => $sub_terms_count, |
| 56 |
]; |
| 57 |
} |
| 58 |
} |
| 59 |
|