
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

/* -----------------------------------------------------------------------------
 * Get Archive Blog Layout
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_archive_blog_layout' ) ) {
	function presso_get_archive_blog_layout() {
		$archive_blog_layout = presso_get_theme_option( 'blog_loop_layout' );

		if ( is_archive() ) {
			$archive_blog_layout = presso_get_theme_option( 'archive_loop_layout' );

		} elseif ( is_search() ) {
			$archive_blog_layout = presso_get_theme_option( 'search_loop_layout' );
		}

		return apply_filters( 'presso_filter_get_archive_blog_layout', $archive_blog_layout );
	}
}


/* -----------------------------------------------------------------------------
 * Get Archive Title
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_archive_title' ) ) {
	function presso_get_archive_title() {

		if ( is_author() ) {	
			$title = get_the_author_meta( 'display_name' );

		} elseif ( is_post_type_archive() ) {
			$title = post_type_archive_title();
		
		} else if ( is_tax( 'post_format' ) ) {
			if ( is_tax( 'post_format', 'post-format-video' ) ) {
				$title = esc_html__( 'Videos', 'presso' );

			} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
				$title = esc_html__( 'Audios', 'presso' );

			} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
				$title = esc_html__( 'Galleries', 'presso' );

			}

		} else if ( is_tax( 'presso_gallery_cat' ) || is_tax( 'presso_portfolio_cat' ) ) {
			global $wp_query;
			$term = $wp_query->get_queried_object();
			$title = $term->name;

		} elseif ( is_tax() || is_category() || is_tag() ) {
			$title = single_term_title( '', false );

		} else {
			$title = esc_html__( 'Archives', 'presso' );

		}

		return apply_filters( 'presso_filter_archive_title', $title );
	}
}

if ( ! function_exists( 'presso_the_archive_title' ) ) {
	function presso_the_archive_title() {
		$title = presso_get_archive_title();

		// Render Title
		if ( ! empty( $title ) ) {
			echo esc_html( $title );
		}
	}
}



if ( ! function_exists( 'presso_the_archive_tagline' ) ) {
	function presso_the_archive_tagline( $classes='vw-tagline' ) {
		$tagline = '';
		
		if ( is_category() || is_tag() ) {
			$tagline = apply_filters( 'presso_filter_archive_tagline', term_description() );

		} else if ( is_tax( 'presso_gallery_cat' ) ) {
			global $wp_query;
			$term = $wp_query->get_queried_object();

			$tagline = apply_filters( 'presso_filter_archive_tagline', term_description( $term->term_id, 'presso_gallery_cat' ) );
		}

		// Render Title
		if ( ! empty( $tagline ) ) {
			?>
			<div class="<?php echo esc_attr( $classes ); ?>"><span><?php echo wp_kses_data( $tagline ); ?></span></div>
			<?php
		}
	}
}



/* -----------------------------------------------------------------------------
 * Get Category Option Proxy
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_archive_category' ) ) {
	function presso_get_archive_category() {
		return get_category( get_query_var('cat') );
	}
}

if ( ! function_exists( 'presso_get_archive_category_id' ) ) {
	function presso_get_archive_category_id() {
		$category = presso_get_archive_category();

		if ( ! empty( $category ) ) {
			return $category->cat_ID;
		} else {
			return '';
		}
	}
}

if ( ! function_exists( 'presso_get_single_cat_id' ) ) {
	function presso_get_single_cat_id() {
		$category = get_the_category();
		if ( ! $category ) return false;

		return $category[0]->term_id;
	}
}

if ( ! function_exists( 'presso_get_category_option' ) ) {
	function presso_get_category_option( $cat_ID, $option_name, $default = null ) {
		$option_name = sprintf( 'category_%s_%s', $cat_ID, $option_name );
		return get_option( $option_name, $default );
	}
}


if ( ! function_exists( 'presso_get_tag_option' ) ) {
	function presso_get_tag_option( $tag_ID, $option_name, $default = null ) {
		$option_name = sprintf( 'tag_%s_%s', $tag_ID, $option_name );
		return get_option( $option_name, $default );
	}
}


if ( ! function_exists( 'presso_get_tax_option' ) ) {
	function presso_get_tax_option( $option_name, $taxonomy='', $term_id=0 ) {
		if ( empty( $taxonomy ) && empty( $term_id ) ) {
			$queried_object = get_queried_object(); 
			$taxonomy = $queried_object->taxonomy;
			$term_id = $queried_object->term_id;
		}

		return get_option( $taxonomy . '_' . $term_id . '_' . $option_name, null );
	}
}





/* -----------------------------------------------------------------------------
 * Get Current Page Number
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_paged' ) ) {
	function presso_get_paged() {
		if ( get_query_var('paged') ) { return intval( get_query_var('paged') ); }
		elseif ( get_query_var('page') ) { return intval( get_query_var('page') ); }
		else { return 1; }
	}
}


/* -----------------------------------------------------------------------------
 * The Pagination
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_pagination' ) ) {
	function presso_the_pagination( $pagination_style = 'show' ) {
		global $presso_secondary_query;
		
		// Don't print empty markup if there's only one page.
		if ( empty( $presso_secondary_query ) || $presso_secondary_query->max_num_pages < 2 ) {
			return;
		}

		$paged        = presso_get_paged();
		$pagenum_link = html_entity_decode( get_pagenum_link() );
		$query_args   = array();
		$url_parts    = explode( '?', $pagenum_link );

		if ( isset( $url_parts[1] ) ) {
			wp_parse_str( $url_parts[1], $query_args );
		}

		$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
		$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';

		$format  = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
		$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';

		// Support offset
		if ( ! empty( $presso_secondary_query->query['offset'] ) ) {
				if ( $paged > 1 ) {
					$actual_offset = $presso_secondary_query->query['offset'] - ( ( $paged - 1 ) * $presso_secondary_query->query['posts_per_page'] );
				} else {
					$actual_offset = $presso_secondary_query->query['offset'];
				}
			
				$total_page = ceil( ( $presso_secondary_query->found_posts - $actual_offset ) / $presso_secondary_query->query['posts_per_page'] );
		} else {
			$total_page = max( 1, $presso_secondary_query->max_num_pages );
		}

		// Set up paginated links.
		$links = '';
		$classes = '';
		$paginate_args = array(
			// 'base'     => $pagenum_link,
			// 'format'   => $format,
			'total'    => $total_page,
			'current'  => $paged,
			'end_size' => 1,
			'mid_size' => 3,
			'add_args' => array_map( 'urlencode', $query_args ),
			'prev_text' => '<span><i class="vw-icon icon-entypo-left-open"></i></span>',
			'next_text' => '<span><i class="vw-icon icon-entypo-right-open"></i></span>',
			'before_page_number' => '<span>',
			'after_page_number'  => '</span>',
		);

		if ( 'infinite' == $pagination_style || 'infinite-auto' == $pagination_style ) {
			$paginate_args['type'] = 'array';
			$paginate_links = paginate_links( $paginate_args );

			if ( ! empty( $paginate_links ) ) {
				$next_link = array_pop( $paginate_links );

				if ( stripos( $next_link, 'next page-numbers' ) ) {
					if ( preg_match( '|http[^"]+|i', $next_link, $matches ) ) {

						if ( 'infinite-auto' == $pagination_style ) {
							$classes .= ' vw-pagination--infinite-auto vw-pagination--append-items';
							$links = '<a class="vw-pagination__load-more vw-button vw-button--small" href="'.esc_url( $matches[0] ).'"><i class="vw-icon icon-entypo-dot-3"></i></a>';
						} else {
							$classes .= ' vw-pagination--infinite vw-pagination--append-items';
							$links = '<a class="vw-pagination__load-more vw-button vw-button--small" href="'.esc_url( $matches[0] ).'">'.esc_html__( 'See More', 'presso' ).'</a>';
						}
					}
				}
				
			}

		} else {
			$classes .= ' vw-pagination--numeric';

			$links = paginate_links( $paginate_args );

		}

		if ( $links ) :
		?>
		<nav class="vw-pagination clearfix <?php echo esc_attr( $classes ); ?>">
			<div class="vw-pagination__links">
				<?php echo $links; ?>
			</div>
		</nav>
		<?php
		endif;
	}
}