<?php
/**
 * The template for displaying custom taxonomy archive pages
 *
 * This template displays posts associated with a custom taxonomy term.
 * It can be overridden by more specific templates like taxonomy-{taxonomy}.php
 * or taxonomy-{taxonomy}-{term}.php
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#taxonomy
 *
 * @package ROI_Theme
 * @since 1.0.0
 */

get_header();
?>

	<main id="main-content" class="site-main" role="main">

		<div class="content-wrapper">

			<!-- Primary Content Area -->
			<div id="primary" class="content-area">

				<?php if ( have_posts() ) : ?>

					<!-- Taxonomy Archive Header -->
					<header class="page-header taxonomy-header">
						<?php
						// Taxonomy title
						the_archive_title( '<h1 class="page-title taxonomy-title">', '</h1>' );

						// Taxonomy description
						$taxonomy_description = get_the_archive_description();
						if ( ! empty( $taxonomy_description ) ) :
							?>
							<div class="archive-description taxonomy-description">
								<?php echo wp_kses_post( wpautop( $taxonomy_description ) ); ?>
							</div>
						<?php endif; ?>

						<!-- Taxonomy metadata -->
						<?php
						$term = get_queried_object();
						if ( $term && isset( $term->count ) ) :
							?>
							<div class="taxonomy-meta">
								<span class="taxonomy-count">
									<?php
									printf(
										/* translators: %s: number of posts */
										esc_html( _n( '%s post', '%s posts', $term->count, 'roi-theme' ) ),
										esc_html( number_format_i18n( $term->count ) )
									);
									?>
								</span>
								<?php if ( isset( $term->taxonomy ) ) : ?>
									<span class="taxonomy-name">
										<?php
										$taxonomy_obj = get_taxonomy( $term->taxonomy );
										if ( $taxonomy_obj ) {
											echo esc_html( $taxonomy_obj->labels->singular_name );
										}
										?>
									</span>
								<?php endif; ?>
							</div>
						<?php endif; ?>
					</header><!-- .page-header -->

					<!-- Taxonomy Posts Loop -->
					<div class="archive-posts taxonomy-posts">

						<?php
						// Start the WordPress Loop
						while ( have_posts() ) :
							the_post();

							/**
							 * Include the Post-Type-specific template for the content.
							 * If you want to override this in a child theme, then include a file
							 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
							 */
							get_template_part( 'template-parts/content', get_post_type() );

						endwhile;
						?>

					</div><!-- .archive-posts -->

					<?php
					/**
					 * Pagination
					 * Display navigation to next/previous set of posts when applicable.
					 */
					the_posts_pagination(
						array(
							'mid_size'  => 2,
							'prev_text' => sprintf(
								'%s <span class="nav-prev-text">%s</span>',
								'<span class="nav-icon" aria-hidden="true">&laquo;</span>',
								esc_html__( 'Previous', 'roi-theme' )
							),
							'next_text' => sprintf(
								'<span class="nav-next-text">%s</span> %s',
								esc_html__( 'Next', 'roi-theme' ),
								'<span class="nav-icon" aria-hidden="true">&raquo;</span>'
							),
							'before_page_number' => '<span class="screen-reader-text">' . esc_html__( 'Page', 'roi-theme' ) . ' </span>',
							'aria_label' => esc_attr__( 'Posts navigation', 'roi-theme' ),
						)
					);

				else :

					/**
					 * No posts found
					 * Display a message when no content is available.
					 */
					get_template_part( 'template-parts/content', 'none' );

				endif;
				?>

			</div><!-- #primary -->

			<?php
			/**
			 * Sidebar
			 * Display the sidebar if it's active.
			 */
			if ( is_active_sidebar( 'sidebar-1' ) ) :
				get_sidebar();
			endif;
			?>

		</div><!-- .content-wrapper -->

	</main><!-- #main-content -->

<?php
get_footer();
