<?php
/**
 * Additional features to allow styling of the templates
 *
 * @subpackage Chiropractor Therapy
 * @since 1.0
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function chiropractor_therapy_body_classes( $classes ) {
	// Add class of group-blog to blogs with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	// Add class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}

	// Add class if we're viewing the Customizer for easier styling of theme options.
	if ( is_customize_preview() ) {
		$classes[] = 'chiropractor-therapy-customizer';
	}

	// Add class on front page.
	if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
		$classes[] = 'chiropractor-therapy-front-page';
	}

	// Add a class if there is a custom header.
	if ( has_header_image() ) {
		$classes[] = 'has-header-image';
	}

	// Add class if sidebar is used.
	if ( is_active_sidebar( 'sidebar-1' ) && ! is_page() ) {
		$classes[] = 'has-sidebar';
	}

	// Add class for one or two column page layouts.
	if ( is_page() || is_archive() ) {
		if ( 'one-column' === get_theme_mod( 'page_layout' ) ) {
			$classes[] = 'page-one-column';
		} else {
			$classes[] = 'page-two-column';
		}
	}

	return $classes;
}
add_filter( 'body_class', 'chiropractor_therapy_body_classes' );

function chiropractor_therapy_is_frontpage() {
	return ( is_front_page() && ! is_home() );
}

/**
 * Pagination for blog post.
 */
function chiropractor_therapy_render_blog_pagination() {
	$chiropractor_therapy_pagination_type = get_theme_mod( 'chiropractor_therapy_pagination_type', 'numbered' );
	if ($chiropractor_therapy_pagination_type == 'default') {
		the_posts_navigation(array(
            'prev_text'          => __( 'Previous page', 'chiropractor-therapy' ),
            'next_text'          => __( 'Next page', 'chiropractor-therapy' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'chiropractor-therapy' ) . ' </span>',
        ) );
	}
	else if($chiropractor_therapy_pagination_type == 'numbered'){
		the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'chiropractor-therapy' ),
            'next_text'          => __( 'Next page', 'chiropractor-therapy' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'chiropractor-therapy' ) . ' </span>',
        ) );
	}
}
add_action( 'chiropractor_therapy_blog_pagination', 'chiropractor_therapy_render_blog_pagination', 10 );

/**
 * Pagination for single post.
 */
function chiropractor_therapy_render_single_post_pagination() {
	$chiropractor_therapy_single_post_pagination_type = get_theme_mod( 'chiropractor_therapy_single_post_pagination_type', 'default' );
	if ($chiropractor_therapy_single_post_pagination_type == 'default') {
		the_post_navigation( array(
			'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'chiropractor-therapy' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'chiropractor-therapy' ) . '</span>',
			'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'chiropractor-therapy' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'chiropractor-therapy' ) . '</span> ',
		) );
	}
	else if($chiropractor_therapy_single_post_pagination_type == 'post-name'){
		the_post_navigation( array(
			'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'chiropractor-therapy' ) . '</span><span class="nav-title">%title</span>',
			'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'chiropractor-therapy' ) . '</span><span class="nav-title">%title</span>',
		) );
	}
}
add_action( 'chiropractor_therapy_single_post_pagination', 'chiropractor_therapy_render_single_post_pagination', 10 );