File Manager
Viewing File: doc-hub.php
<?php
/**
* Doc Hub archive template
*
* Displays a grid of Doc Hubs when the "Display Doc Hubs" setting is enabled.
*
* This template can be overridden by copying it to yourtheme/documentor/doc-hub.php.
*
* @author softaculous
* @package documentor/Templates
* @version 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
documentor()->get_template_part( 'global/wrap-start' );
$hubs = get_terms( array(
'taxonomy' => 'docs_hub',
'hide_empty' => false,
) );
$active_hubs_count = 0;
$boxes_html = '';
if ( ! empty( $hubs ) && ! is_wp_error( $hubs ) ) {
foreach ( $hubs as $hub ) {
$hub_id = $hub->term_id;
$matching_cats = get_terms( array(
'taxonomy' => 'docs_category',
'meta_query' => array(
array(
'key' => 'documentor_associated_hubs',
'value' => $hub_id,
'compare' => '=',
),
),
'fields' => 'ids',
) );
$cat_count = ( ! empty( $matching_cats ) && ! is_wp_error( $matching_cats ) ) ? count( $matching_cats ) : 0;
$tax_query = array( 'relation' => 'OR' );
if ( $cat_count > 0 ) {
$tax_query[] = array(
'relation' => 'AND',
array(
'taxonomy' => 'docs_category',
'field' => 'term_id',
'terms' => $matching_cats,
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'docs_hub',
'field' => 'term_id',
'terms' => $hub_id,
),
array(
'taxonomy' => 'docs_hub',
'operator' => 'NOT EXISTS',
),
),
);
}
$tax_query[] = array(
'relation' => 'AND',
array(
'taxonomy' => 'docs_hub',
'field' => 'term_id',
'terms' => $hub_id,
),
array(
'taxonomy' => 'docs_category',
'operator' => 'NOT EXISTS',
),
);
$docs_query = new WP_Query( array(
'post_type' => 'docs',
'posts_per_page' => -1,
'fields' => 'ids',
'tax_query' => $tax_query,
) );
$doc_count = $docs_query->post_count;
if ( 0 === $cat_count && 0 === $doc_count ) {
continue;
}
$active_hubs_count++;
$page_url = '';
$pages = get_posts( array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => '_documentor_linked_hub_id',
'value' => $hub_id,
),
),
) );
if ( ! empty( $pages ) ) {
$page_url = get_permalink( $pages[0]->ID );
} else {
$page_url = get_term_link( $hub );
}
$cat_text = 1 === $cat_count ? '1 Category' : $cat_count . ' Categories';
$doc_text = 1 === $doc_count ? '1 Doc' : $doc_count . ' Docs';
$boxes_html .= '<a href="' . esc_url( $page_url ) . '" class="documentor-hub-box">';
$boxes_html .= '<span class="documentor-hub-title">' . esc_html( $hub->name ) . '</span>';
$boxes_html .= '<span class="documentor-hub-meta">' . $cat_text . ' • ' . $doc_text . '</span>';
$boxes_html .= '</a>';
}
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php documentor()->get_template_part( 'archive/title' ); ?>
<?php if ( documentor()->get_option( 'sidebar_show_search', 'documentor_single', true ) ) : ?>
<div class="home_search" style="text-align:center;">
<form role="search" method="get" class="documentor-search-form width_control" action="<?php echo esc_url( home_url( $wp->request ) ); ?>">
<input type="search" class="documentor-search-field search_form_index" placeholder="<?php echo esc_attr__( 'Type to search', 'documentor' ); ?>" value="<?php echo get_search_query(); ?>" name="s" autocomplete="off">
<input type="hidden" name="post_type" value="docs">
</form>
<div class="documentor-search-form-result search_on_index"></div>
</div>
<?php endif; ?>
<div class="documentor-archive">
<?php if ( $active_hubs_count > 0 ) : ?>
<div class="documentor-hub-grid"><?php echo $boxes_html; ?></div>
<?php else : ?>
<p><?php esc_html_e( 'No Doc Hub found', 'documentor' ); ?></p>
<?php endif; ?>
</div>
</div>
</article>
<?php
documentor()->get_template_part( 'global/wrap-end' );