<?php

/**
 * Decide how to display Post Thumbnail
 *
 * If standard post, quote, image, use featured image,
 * video and audio won't display featured image.
 */
if( !function_exists('wishbone_post_media') ){
	function wishbone_post_media(){
		global $post;
		$format = get_post_format();
		if ( false === $format || 'image' == $format ) {
			if( has_post_thumbnail() ){
	            if( 'image' == $format ){
	                $thumbid = get_post_thumbnail_id();
	                $linkto = wp_get_attachment_url( $thumbid );
	            } else {
	                $linkto = get_permalink();
	            }
				echo '<div class="wishbone_postthumb">';
				if( !is_single() ){
					echo '<a href="'. esc_url( $linkto ) .'">'."\n";
				}
					the_post_thumbnail('wishbone_wide_featured');
				if( !is_single() ){
					echo '</a>';
				}
				echo '</div>';
			}
		}

		elseif( 'gallery' == $format ){
			$items = wishbone_meta('gallery');
			$gallerytype = wishbone_meta('gallerytype', '');

			/* Slideshow */
			if(!empty($items) && 'slideshow' == $gallerytype){
				echo '<div class="owl-carousel post-gallery">';
				foreach ($items as $item) {
					$item_id = $caption = '';

					$item_id =  $item['attachment_id'];
					$metadata =  get_post( $item_id );

					$image_size = 'wishbone_wide_featured';
					$rawurl = wp_get_attachment_image_src( $item_id, $image_size );
					$linkto = wp_get_attachment_url( $item_id );
					$image_url = $rawurl[0];
					echo '<div>';
					echo '<a href="'.esc_url( $linkto ).'">';
					echo '<img src="'.esc_url( $image_url ).'" alt="" />';
					echo '</a>';
					if($metadata->post_excerpt){
						echo '<div class="wishbone_post_gallery_caption">'.esc_html( $metadata->post_excerpt ).'</div>';
					}
					echo '</div>';
				}
				echo '</div>';
			} elseif( !empty($items) && 'grid' == $gallerytype ){
				echo '<div class="gallery-grid" id="grid-'.get_the_ID().'">';
				foreach ($items as $item) {
					$item_id = $caption = '';

					$item_id =  $item['attachment_id'];
					$metadata =  get_post( $item_id );

					$image_size = 'medium';
					$rawurl = wp_get_attachment_image_src( $item_id, $image_size );
					$linkto = wp_get_attachment_url( $item_id );
					$image_url = $rawurl[0];
					echo '<a href="'.esc_url( $linkto ).'">';
					echo '<img src="'.esc_url($image_url).'" alt="'.esc_attr($metadata->post_excerpt).'" />';
					echo '</a>';
					if($metadata){
						//echo '<div class="wishbone_post_gallery_caption">'.$metadata->post_excerpt.'</div>';
					}
				}
				echo '</div><div class="clear"></div>';
			}
		}

		elseif( 'audio' == $format ){
			$audio = wishbone_meta('audio');
			if( !empty($audio) ){
				$type = $url = $file = $iframe = '';

				if( !empty($audio['type']) ){
					$type = $audio['type'];
				}

				if( !empty($audio['url']['url']) ){
					$url = $audio['url']['url'];
				}

				if( !empty($audio['upload']['upload']['url']) ){
					$file = $audio['upload']['upload']['url'];
				}

				if( !empty($audio['iframe']['iframe']) ){
					$iframe = $audio['iframe']['iframe'];
				}

				/* URL EMBED */
				if( 'url' == $type ){
					echo wp_oembed_get($url, array('width'=>840));
				}

				elseif( 'upload' == $type ){
					if( has_post_thumbnail() ){
			            if( 'image' == $format ){
			                $thumbid = get_post_thumbnail_id();
			                $linkto = wp_get_attachment_url( $thumbid );
			            } else {
			                $linkto = get_permalink();
			            }
						echo '<div class="wishbone_postthumb">';
						if( !is_single() ){
							echo '<a href="'. esc_url( $linkto ) .'">'."\n";
						}
							the_post_thumbnail('wishbone_post_thumb');
						if( !is_single() ){
							echo '</a>';
						}
						echo '</div>';
					}
					echo do_shortcode( '[audio src="'. $file .'" preload="metadata"]' );
				}

				elseif( 'iframe' == $type ){
					echo wishbone_pass_html( $iframe );
				}

			}
		}

		elseif( 'video' == $format ){
			$video = wishbone_meta('video');
			if( !empty($video) ){

				if( !empty($video['type']) ){
					$type = $video['type'];
				}

				if( !empty($video['url']['url']) ){
					$url = $video['url']['url'];
				}

				if( !empty($video['upload']['upload']['url']) ){
					$file = $video['upload']['upload']['url'];
				}

				if( !empty($video['iframe']['iframe']) ){
					$iframe = $video['iframe']['iframe'];
				}

				/* URL EMBED */
				if( 'url' == $type ){
					echo wp_oembed_get($url, array('width'=>840));
				}

				elseif( 'upload' == $type ){
					if( has_post_thumbnail() ){
			            $thumbid = get_post_thumbnail_id();
						$image_size = 'wishbone_post_thumb';
						$rawurl = wp_get_attachment_image_src( $thumbid, $image_size );
					}
					echo do_shortcode( '[video src="'. $file .'" preload="metadata" width="840" poster="'. $rawurl[0] .'"]' );
				}

				elseif( 'iframe' == $type ){
					echo wishbone_pass_html( $iframe );
				}

			}
		}

	    if( is_attachment() ){
	        $thumb = get_post_thumbnail_id();
	        $thispageid = get_the_ID();
	        $img_url = wp_get_attachment_url();
	        echo '<img src="'. $img_url .'" alt=""/>';
	    }
	}
}

/**
 * Linear Icons
 */
function lnr_icon( $class = null ){
	?>
	<svg class="lnr <?php echo esc_attr( $class ); ?>"><use xlink:href="<?php echo get_template_directory_uri(); ?>/assets/svg/svgdefs.svg#<?php echo esc_attr( $class ); ?>"></use></svg>
	<?php
}

/**
 * Linear Icons
 */
function lnr_icon_raw( $class = null ){
	$icon = '<svg class="lnr '.esc_attr( $class ).'"><use xlink:href="'. get_template_directory_uri().'/assets/svg/svgdefs.svg#'.esc_attr( $class ).'"></use></svg>';
	?>

	<?php
	return $icon;
}

/**
 * Post icon to define what post format
 */
function wishbone_postsymbol(){

	if( 'image' == get_post_format() ){
		$icon = 'lnr-camera';
	} elseif( 'video' == get_post_format() ){
		$icon = 'lnr-film-play';
	} elseif( 'audio' == get_post_format() ){
		$icon = 'lnr-music-note';
	} elseif( 'gallery' == get_post_format() ){
		$icon = 'lnr-picture';
	} else {
		$icon = 'lnr-file-empty';
	}

	lnr_icon( $icon );
}

/**
 * MOBILE Carousel
 */
function wishbone_mobile_carousel($items = null, $widetags = null){
	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'order'=> 'DESC',
		'ignore_sticky_posts' => 1,
		'orderby'=> 'DATE',
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))
	);

	$slider = new WP_Query( $args );
	if( $slider->have_posts() ):

	?>

		<div class="hide-for-medium-up">
			<div class="owl-carousel wishbone_m_carousel">
				<?php while( $slider->have_posts() ): $slider->the_post(); ?>
					<div>
						<a href="<?php the_permalink(); ?>">
							<?php
							if( has_post_thumbnail() ){
								the_post_thumbnail('medium');
							}
							 ?>
						</a>
						<div class="wishbone_m_crsl_desc">
							<?php the_category(', ') ?>
							<h2>
								<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
							</h2>
						</div>
					</div>
				<?php endwhile; ?>
			</div>
		</div>

	<?php
	wp_reset_postdata();
	endif; // $slider->have_posts()
}

/**
 * Wishbone Carousel
 */
function wishbone_wishbone_carousel( $items = null, $widetags = null ){

	wishbone_mobile_carousel( $items, $widetags );

	if( wp_is_mobile() ) return false;

	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'order'=> 'DESC',
		'ignore_sticky_posts' => 1,
		'orderby'=> 'DATE',
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))
	);

	$slider = new WP_Query( $args );
	if( $slider->have_posts() ):

	?>
	<!-- ===================================
	CAROUSEL
	===================================== -->
	<div class="wishbone_herosliderwrapper hide-for-small-down">
		<div class="cssload-spinner"></div>
		<div class="owl-carousel wishbone_heroslider">

			<?php while( $slider->have_posts() ): $slider->the_post(); ?>
				<div class="wishbone_slideitem" id="slide-<?php the_ID(); ?>">
					<a href="<?php the_permalink(); ?>">
						<?php if( has_post_thumbnail() ) the_post_thumbnail( 'wishbone_wishbonecarousel' ); ?>
					</a>

					<!-- Details -->
					<div class="wishbone_slidehead">
						<div class="wishbone_slidemeta">
							<?php the_category( ' ' ); ?>
						</div>
						<h3><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h3>
					</div>
					<div class="wishbone_gh_formaticon">
						<?php wishbone_postsymbol(); ?>
					</div>
				</div>
			<?php endwhile; ?>

		</div><!-- End .wishbone_heroslider -->
	</div><!-- End .wishbone_heroslider -->
	<?php
	wp_reset_postdata();
	endif; //$slider->have_posts()

}

/**
 * Wishbone Wide Carousel
 */
function wishbone_wideslider( $items = null, $widetags = null ){
	wishbone_mobile_carousel( $items, $widetags );

	if( wp_is_mobile() ) return false;

	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'ignore_sticky_posts' => 1,
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))
	);

	?>


	<div class="wishbone_widesliderwrapper hide-for-small-down">
		<div class="cssload-spinner"></div>
		<div class="wishbone_wideslider owl-carousel">
			<?php
			$bigone = new WP_Query( $args );

			if( $bigone->have_posts() ):
				$i=0;
				while( $bigone->have_posts() ): $bigone->the_post();
			 ?>
				<div class="wishbone_ws_item" data-bigthumbid="<?php echo esc_attr( $i ); ?>">
					<div class="wishbone_ws_image">
						<a href="<?php the_permalink(); ?>">
							<?php
								if( has_post_thumbnail() ) the_post_thumbnail( 'wishbone_wishbonewideslider' );
							?>
						</a>
						<div class="wishbone_gh_formaticon">
							<?php wishbone_postsymbol(); ?>
						</div>
					</div>
				</div>
			<?php
				$i++;
				endwhile;
				wp_reset_postdata();
			endif;
			?>
		</div>

		<div class="wishbone_ws_syncronize">
			<div class="wishbone_ws_detailswrapper">
				<div class="wishbone_ws_detailsslider owl-carousel">
					<?php
					$details = new WP_Query( $args );
					if( $details->have_posts() ):
						$i=0;
						while( $details->have_posts() ): $details->the_post();
					 ?>
					<div class="wishbone_ws_detailitem" data-slidedetail="<?php echo esc_attr( $i ); ?>">
						<div class="wishbone_ws_cat">
							<?php the_category( ' ' ); ?>
						</div>
						<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
						<div class="wishbone_ws_date">
							<?php esc_html_e('Published on', 'jt-wishbone'); ?>
							<?php echo get_the_time(get_option('date_format'), get_the_ID() ); ?>
						</div>
					</div>
					<?php
						$i++;
						endwhile;
						wp_reset_postdata();
					endif;
					?>
				</div>
			</div>
			<div class="wishbone_ws_thumbswrapper">
				<?php
				$thumbs = new WP_Query( $args );
				if( $thumbs->have_posts() ):
					$i=0;
					while( $thumbs->have_posts() ): $thumbs->the_post();
				 ?>
				<div class="wishbone_ws_slide_trigger" data-targetid="<?php echo esc_attr($i); ?>">
					<?php
						if( has_post_thumbnail() ) the_post_thumbnail( 'medium' );
					?>
				</div>
				<?php
					$i++;
					endwhile;
					wp_reset_postdata();
				endif;
				?>
				<div class="clear"></div>
			</div>
		</div>
	</div>


	<?php
}

/**
 * Wishbone Grid Hero
 */
function wishbone_gridhero( $items = null, $widetags = null ){

	wishbone_mobile_carousel( $items, $widetags );

	if( wp_is_mobile() ) return false;

	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'order'=> 'DESC',
		'ignore_sticky_posts' => 1,
		'orderby'=> 'date',
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))

	);

	$grid = new WP_Query( $args );

	if( $grid->have_posts() ):
		echo '<div class="wishbone_gridherowrapper hide-for-small-down">';
		echo '<div class="cssload-spinner"></div>';
		$pijet=0;
		while( $grid->have_posts() ): $grid->the_post();

		$isbig = $img = '';

		if( 0 == $pijet ){
			$isbig = ' wishbone_gh_big';
		} else {
			$isbig = '';
		}

		if( 5 == $pijet ) break; ?>

		<div class="wishbone_gh_item<?php echo esc_attr( $isbig ); ?>">
			<a href="<?php the_permalink(); ?>">
				<?php if( has_post_thumbnail() ){ ?>
					<?php if( 0 == $pijet ){ ?>
						<?php the_post_thumbnail( 'wishbone_wishbonegridbig' ); ?>
					<?php } else { ?>
						<?php the_post_thumbnail( 'wishbone_wishbonegridsmall' ); ?>
					<?php } ?>
				<?php } ?>
			</a>
			<div class="wishbone_gh_formaticon">
				<?php wishbone_postsymbol(); ?>
			</div>
			<div class="wishbone_gh_cover">
				<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				<ul class="wishbone_gh_meta">
					<li>
						<?php lnr_icon('lnr-clock'); ?>
						<?php printf( _x( '%s ago', '%s = human-readable time difference', 'jt-wishbone' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) ); ?>
					</li>
				</ul>
			</div>
		</div>
	<?php
		$pijet++;
		endwhile;
		wp_reset_postdata();
		echo '<div class="clear"></div>';
		echo '</div>';
	endif;
}

/**
 * Wishbone 1 Columns Slider
 */
function wishbone_onecol_slider( $items = null, $widetags = null ){

	wishbone_mobile_carousel( $items, $widetags );

	if( wp_is_mobile() ) return false;

	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'order'=> 'DESC',
		'ignore_sticky_posts' => 1,
		'orderby'=> 'date',
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))
	);

	$wishbone_onecol_slider = new WP_Query( $args );

	if( $wishbone_onecol_slider->have_posts() ):
		echo '<div class="wishbone_onecol_sliderwrapper hide-for-small-down">';
		echo '<div class="cssload-spinner"></div>';
		echo '<div class="wishbone_onecol_slider owl-carousel">';
		$pijet=0;
		while( $wishbone_onecol_slider->have_posts() ): $wishbone_onecol_slider->the_post();
	?>

		<div class="wishbone_ts_item">
			
			<div class="wishbone_verywidethumb">
				<a href="<?php the_permalink(); ?>">
				<?php
					if( has_post_thumbnail() ){
						the_post_thumbnail(  );
				 	}
				 ?>
			</a>
			</div>
			<div class="wishbone_ts_formicon">
				<?php wishbone_postsymbol(); ?>
			</div>
			<div class="wishbone_ts_cover">
				<div class="row">
					<div class="large-12 column">
						<div class="wishbone_ts_date">
							<div class="wishbone_ts_day">
								<?php echo get_the_date( 'd' ) ?>
							</div>
							<div class="wishbone_ts_month">
								<?php echo get_the_date( 'M' ) ?>
							</div>
						</div>
						<div class="wishbone_ts_title">
							<div class="wishbone_ts_cat">
								<?php lnr_icon( 'lnr-bookmark' ) .' '. the_category( ', ' ) ?>
							</div>
							<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
							<?php the_excerpt(); ?>
						</div>
					</div>
				</div>
			</div>
		</div>

	<?php
		$pijet++;
		endwhile;
		wp_reset_postdata();
		echo '</div> <!-- wishbone_twocol_slider -->';
		echo '</div> <!-- wishbone_twocol_sliderwrapper -->';
	endif;
}


/**
 * Wishbone 2 Columns Slider
 */
function wishbone_twocol_slider( $items = null, $widetags = null ){

	wishbone_mobile_carousel( $items, $widetags );

	if( wp_is_mobile() ) return false;

	if( !empty( $items ) ){
		$fetchnumber = $items;
	} else {
		$fetchnumber = '6';
	}

	if( !empty( $widetags ) ){
		$tags = $widetags;
	} else {
		$tags = null;
	}

	$args = array(
		'post_type' => 'post',
		'order'=> 'DESC',
		'ignore_sticky_posts' => 1,
		'orderby'=> 'date',
		'tag__in' => $tags,
		'posts_per_page' => $fetchnumber,
		'meta_query' => array(array('key' => '_thumbnail_id'))
	);

	$wishbone_twocol_slider = new WP_Query( $args );

	if( $wishbone_twocol_slider->have_posts() ):
		echo '<div class="wishbone_twocol_sliderwrapper hide-for-small-down">';
		echo '<div class="cssload-spinner"></div>';
		echo '<div class="wishbone_twocol_slider owl-carousel">';
		$pijet=0;
		while( $wishbone_twocol_slider->have_posts() ): $wishbone_twocol_slider->the_post();
	?>

		<div class="wishbone_ts_item">
			<a href="<?php the_permalink(); ?>">
				<?php
					if( has_post_thumbnail() ){
						the_post_thumbnail( 'large' );
				 	}
				 ?>
			</a>
			<div class="wishbone_ts_formicon">
				<?php wishbone_postsymbol(); ?>
			</div>
			<div class="wishbone_ts_cover">
				<div class="wishbone_ts_date">
					<div class="wishbone_ts_day">
						<?php echo get_the_date( 'd' ) ?>
					</div>
					<div class="wishbone_ts_month">
						<?php echo get_the_date( 'M' ) ?>
					</div>
				</div>
				<div class="wishbone_ts_title">
					<div class="wishbone_ts_cat">
						<?php lnr_icon( 'lnr-bookmark' ) .' '. the_category( ', ' ) ?>
					</div>
					<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				</div>
			</div>
		</div>

	<?php
		$pijet++;
		endwhile;
		wp_reset_postdata();
		echo '</div> <!-- wishbone_twocol_slider -->';
		echo '</div> <!-- wishbone_twocol_sliderwrapper -->';
	endif;
}



/**
 * Post Views
 */
// function to display number of posts.
function wishbone_getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0";
    }
    return $count;
}

// function to count views.
function wishbone_setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}


/*
Name:  WordPress Post Like System
Description:  A simple and efficient post like system for WordPress.
Version:      0.5.2
Author:       Jon Masterson
Author URI:   http://jonmasterson.com/
License:
Copyright (C) 2015 Jon Masterson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * Processes like/unlike
 * @since    0.5
 */
add_action( 'wp_ajax_nopriv_wishbone_process_simple_like', 'wishbone_process_simple_like' );
add_action( 'wp_ajax_wishbone_process_simple_like', 'wishbone_process_simple_like' );
function wishbone_process_simple_like() {
	// Security
	$nonce = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( $_REQUEST['nonce'] ) : 0;
	if ( !wp_verify_nonce( $nonce, 'simple-likes-nonce' ) ) {
		exit( esc_html__( 'Not permitted', 'jt-wishbone' ) );
	}
	// Test if javascript is disabled
	$disabled = ( isset( $_REQUEST['disabled'] ) && $_REQUEST['disabled'] == true ) ? true : false;
	// Test if this is a comment
	$is_comment = ( isset( $_REQUEST['is_comment'] ) && $_REQUEST['is_comment'] == 1 ) ? 1 : 0;
	// Base variables
	$post_id = ( isset( $_REQUEST['post_id'] ) && is_numeric( $_REQUEST['post_id'] ) ) ? $_REQUEST['post_id'] : '';
	$result = array();
	$post_users = NULL;
	$like_count = 0;
	// Get plugin options
	if ( $post_id != '' ) {
		$count = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_comment_like_count", true ) : get_post_meta( $post_id, "_post_like_count", true ); // like count
		$count = ( isset( $count ) && is_numeric( $count ) ) ? $count : 0;
		if ( !wishbone_already_liked( $post_id, $is_comment ) ) { // Like the post
			if ( is_user_logged_in() ) { // user is logged in
				$user_id = get_current_user_id();
				$post_users = wishbone_post_user_likes( $user_id, $post_id, $is_comment );
				if ( $is_comment == 1 ) {
					// Update User & Comment
					$user_like_count = get_user_option( "_comment_like_count", $user_id );
					$user_like_count =  ( isset( $user_like_count ) && is_numeric( $user_like_count ) ) ? $user_like_count : 0;
					update_user_option( $user_id, "_comment_like_count", ++$user_like_count );
					if ( $post_users ) {
						update_comment_meta( $post_id, "_user_comment_liked", $post_users );
					}
				} else {
					// Update User & Post
					$user_like_count = get_user_option( "_user_like_count", $user_id );
					$user_like_count =  ( isset( $user_like_count ) && is_numeric( $user_like_count ) ) ? $user_like_count : 0;
					update_user_option( $user_id, "_user_like_count", ++$user_like_count );
					if ( $post_users ) {
						update_post_meta( $post_id, "_user_liked", $post_users );
					}
				}
			} else { // user is anonymous
				$user_ip = wishbone_sl_get_ip();
				$post_users = wishbone_post_ip_likes( $user_ip, $post_id, $is_comment );
				// Update Post
				if ( $post_users ) {
					if ( $is_comment == 1 ) {
						update_comment_meta( $post_id, "_user_comment_IP", $post_users );
					} else {
						update_post_meta( $post_id, "_user_IP", $post_users );
					}
				}
			}
			$like_count = ++$count;
			$response['status'] = "liked";
			$response['icon'] = wishbone_get_liked_icon();
		} else { // Unlike the post
			if ( is_user_logged_in() ) { // user is logged in
				$user_id = get_current_user_id();
				$post_users = wishbone_post_user_likes( $user_id, $post_id, $is_comment );
				// Update User
				if ( $is_comment == 1 ) {
					$user_like_count = get_user_option( "_comment_like_count", $user_id );
					$user_like_count =  ( isset( $user_like_count ) && is_numeric( $user_like_count ) ) ? $user_like_count : 0;
					if ( $user_like_count > 0 ) {
						update_user_option( $user_id, "_comment_like_count", --$user_like_count );
					}
				} else {
					$user_like_count = get_user_option( "_user_like_count", $user_id );
					$user_like_count =  ( isset( $user_like_count ) && is_numeric( $user_like_count ) ) ? $user_like_count : 0;
					if ( $user_like_count > 0 ) {
						update_user_option( $user_id, '_user_like_count', --$user_like_count );
					}
				}
				// Update Post
				if ( $post_users ) {
					$uid_key = array_search( $user_id, $post_users );
					unset( $post_users[$uid_key] );
					if ( $is_comment == 1 ) {
						update_comment_meta( $post_id, "_user_comment_liked", $post_users );
					} else {
						update_post_meta( $post_id, "_user_liked", $post_users );
					}
				}
			} else { // user is anonymous
				$user_ip = wishbone_sl_get_ip();
				$post_users = wishbone_post_ip_likes( $user_ip, $post_id, $is_comment );
				// Update Post
				if ( $post_users ) {
					$uip_key = array_search( $user_ip, $post_users );
					unset( $post_users[$uip_key] );
					if ( $is_comment == 1 ) {
						update_comment_meta( $post_id, "_user_comment_IP", $post_users );
					} else {
						update_post_meta( $post_id, "_user_IP", $post_users );
					}
				}
			}
			$like_count = ( $count > 0 ) ? --$count : 0; // Prevent negative number
			$response['status'] = "unliked";
			$response['icon'] = wishbone_get_unliked_icon();
		}
		if ( $is_comment == 1 ) {
			update_comment_meta( $post_id, "_comment_like_count", $like_count );
			update_comment_meta( $post_id, "_comment_like_modified", date( 'Y-m-d H:i:s' ) );
		} else {
			update_post_meta( $post_id, "_post_like_count", $like_count );
			update_post_meta( $post_id, "_post_like_modified", date( 'Y-m-d H:i:s' ) );
		}
		$response['count'] = wishbone_get_like_count( $like_count );
		$response['testing'] = $is_comment;
		if ( $disabled == true ) {
			if ( $is_comment == 1 ) {
				wp_redirect( get_permalink( get_the_ID() ) );
				exit();
			} else {
				wp_redirect( get_permalink( $post_id ) );
				exit();
			}
		} else {
			wp_send_json( $response );
		}
	}
}

/**
 * Utility to test if the post is already liked
 * @since    0.5
 */
function wishbone_already_liked( $post_id, $is_comment ) {
	$post_users = NULL;
	$user_id = NULL;
	if ( is_user_logged_in() ) { // user is logged in
		$user_id = get_current_user_id();
		$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_liked" ) : get_post_meta( $post_id, "_user_liked" );
		if ( count( $post_meta_users ) != 0 ) {
			$post_users = $post_meta_users[0];
		}
	} else { // user is anonymous
		$user_id = wishbone_sl_get_ip();
		$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_IP" ) : get_post_meta( $post_id, "_user_IP" );
		if ( count( $post_meta_users ) != 0 ) { // meta exists, set up values
			$post_users = $post_meta_users[0];
		}
	}
	if ( is_array( $post_users ) && in_array( $user_id, $post_users ) ) {
		return true;
	} else {
		return false;
	}
} // wishbone_already_liked()

/**
 * Output the like button
 * @since    0.5
 */
function wishbone_get_simple_likes_button( $post_id, $is_comment = NULL ) {
	$is_comment = ( NULL == $is_comment ) ? 0 : 1;
	$output = '';
	$nonce = wp_create_nonce( 'simple-likes-nonce' ); // Security
	if ( $is_comment == 1 ) {
		$post_id_class = esc_attr( ' sl-comment-button-' . $post_id );
		$comment_class = esc_attr( ' sl-comment' );
		$like_count = get_comment_meta( $post_id, "_comment_like_count", true );
		$like_count = ( isset( $like_count ) && is_numeric( $like_count ) ) ? $like_count : 0;
	} else {
		$post_id_class = esc_attr( ' sl-button-' . $post_id );
		$comment_class = esc_attr( '' );
		$like_count = get_post_meta( $post_id, "_post_like_count", true );
		$like_count = ( isset( $like_count ) && is_numeric( $like_count ) ) ? $like_count : 0;
	}
	$count = wishbone_get_like_count( $like_count );
	$icon_empty = wishbone_get_unliked_icon();
	$icon_full = wishbone_get_liked_icon();
	// Loader
	$loader = '<span class="sl-loader"></span>';
	// Liked/Unliked Variables
	if ( wishbone_already_liked( $post_id, $is_comment ) ) {
		$class = esc_attr( ' liked' );
		$title = esc_html__( 'Unlike', 'jt-wishbone' );
		$icon = $icon_full;
	} else {
		$class = '';
		$title = esc_html__( 'Like', 'jt-wishbone' );
		$icon = $icon_empty;
	}
	$output = '<span class="sl-wrapper"><a href="' . admin_url( 'admin-ajax.php?action=wishbone_process_simple_like' . '&nonce=' . $nonce . '&post_id=' . $post_id . '&disabled=true&is_comment=' . $is_comment ) . '" class="sl-button' . $post_id_class . $class . $comment_class . '" data-nonce="' . $nonce . '" data-post-id="' . $post_id . '" data-iscomment="' . $is_comment . '" title="' . $title . '">' . $icon . $count . '</a>' . $loader . '</span>';
	return $output;
} // wishbone_get_simple_likes_button()

/**
 * Utility retrieves post meta user likes (user id array),
 * then adds new user id to retrieved array
 * @since    0.5
 */
function wishbone_post_user_likes( $user_id, $post_id, $is_comment ) {
	$post_users = '';
	$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_liked" ) : get_post_meta( $post_id, "_user_liked" );
	if ( count( $post_meta_users ) != 0 ) {
		$post_users = $post_meta_users[0];
	}
	if ( !is_array( $post_users ) ) {
		$post_users = array();
	}
	if ( !in_array( $user_id, $post_users ) ) {
		$post_users['user-' . $user_id] = $user_id;
	}
	return $post_users;
} // wishbone_post_user_likes()

/**
 * Utility retrieves post meta ip likes (ip array),
 * then adds new ip to retrieved array
 * @since    0.5
 */
function wishbone_post_ip_likes( $user_ip, $post_id, $is_comment ) {
	$post_users = '';
	$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_IP" ) : get_post_meta( $post_id, "_user_IP" );
	// Retrieve post information
	if ( count( $post_meta_users ) != 0 ) {
		$post_users = $post_meta_users[0];
	}
	if ( !is_array( $post_users ) ) {
		$post_users = array();
	}
	if ( !in_array( $user_ip, $post_users ) ) {
		$post_users['ip-' . $user_ip] = $user_ip;
	}
	return $post_users;
} // wishbone_post_ip_likes()

/**
 * Utility to retrieve IP address
 * @since    0.5
 */
function wishbone_sl_get_ip() {
	if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) && ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} else {
		$ip = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
	}
	$ip = filter_var( $ip, FILTER_VALIDATE_IP );
	$ip = ( $ip === false ) ? '0.0.0.0' : $ip;
	return $ip;
} // wishbone_sl_get_ip()

/**
 * Utility returns the button icon for "like" action
 * @since    0.5
 */
function wishbone_get_liked_icon() {
	/* If already using Font Awesome with your theme, replace svg with: <i class="fa fa-heart"></i> */
	$icon = '<span class="sl-icon likedicon"><svg class="lnr lnr-heart"><use xlink:href="'. get_template_directory_uri() .'/assets/svg/svgdefs.svg#lnr-heart"></use></svg></span> ';
	return $icon;
} // wishbone_get_liked_icon()

/**
 * Utility returns the button icon for "unlike" action
 * @since    0.5
 */
function wishbone_get_unliked_icon() {
	/* If already using Font Awesome with your theme, replace svg with: <i class="fa fa-heart-o"></i> */
	$icon = '<span class="sl-icon"><svg class="lnr lnr-heart"><use xlink:href="'. get_template_directory_uri() .'/assets/svg/svgdefs.svg#lnr-heart"></use></svg></span> ';
	return $icon;
} // wishbone_get_unliked_icon()

/**
 * Utility function to format the button count,
 * appending "K" if one thousand or greater,
 * "M" if one million or greater,
 * and "B" if one billion or greater (unlikely).
 * $precision = how many decimal points to display (1.25K)
 * @since    0.5
 */
function wishbone_sl_format_count( $number ) {
	$precision = 2;
	if ( $number >= 1000 && $number < 1000000 ) {
		$formatted = number_format( $number/1000, $precision ).'K';
	} else if ( $number >= 1000000 && $number < 1000000000 ) {
		$formatted = number_format( $number/1000000, $precision ).'M';
	} else if ( $number >= 1000000000 ) {
		$formatted = number_format( $number/1000000000, $precision ).'B';
	} else {
		$formatted = $number; // Number is less than 1000
	}
	$formatted = str_replace( '.00', '', $formatted );
	return $formatted;
} // wishbone_sl_format_count()

/**
 * Utility retrieves count plus count options,
 * returns appropriate format based on options
 * @since    0.5
 */
function wishbone_get_like_count( $like_count ) {
	$like_text = esc_html__( 'Like', 'jt-wishbone' );
	if ( is_numeric( $like_count ) && $like_count > 0 ) {
		$number = wishbone_sl_format_count( $like_count );
	} else {
		$number = $like_text;
	}
	$count = '<span class="sl-count">' . $number . '</span>';
	return $count;
} // wishbone_get_like_count()

// User Profile List
add_action( 'show_user_profile', 'wishbone_show_user_likes' );
add_action( 'edit_user_profile', 'wishbone_show_user_likes' );
function wishbone_show_user_likes( $user ) { ?>
	<table class="form-table">
		<tr>
			<th><label for="user_likes"><?php esc_html_e( 'You Like:', 'jt-wishbone' ); ?></label></th>
			<td>
			<?php
			$types = get_post_types( array( 'public' => true ) );
			$args = array(
			  'numberposts' => -1,
			  'post_type' => $types,
			  'meta_query' => array (
				array (
				  'key' => '_user_liked',
				  'value' => $user->ID,
				  'compare' => 'LIKE'
				)
			  ) );
			$sep = '';
			$like_query = new WP_Query( $args );
			if ( $like_query->have_posts() ) : ?>
			<p>
			<?php while ( $like_query->have_posts() ) : $like_query->the_post();
			echo esc_html( $sep );; ?><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
			<?php
			$sep = ' &middot; ';
			endwhile;
			?>
			</p>
			<?php else : ?>
			<p><?php esc_html_e( 'You do not like anything yet.', 'jt-wishbone' ); ?></p>
			<?php
			endif;
			wp_reset_postdata();
			?>
			</td>
		</tr>
	</table>
<?php } // wishbone_show_user_likes()


// Add it to a column in WP-Admin
add_filter('manage_posts_columns', 'wishbone_posts_column_likes');
add_action('manage_posts_custom_column', 'wishbone_posts_custom_column_likes',10,2);
function wishbone_posts_column_likes( $defaults ){
    $defaults['post_likes'] = esc_html__('Likes', 'jt-wishbone');
    return $defaults;
}
function wishbone_posts_custom_column_likes( $column_name, $id ){
    if($column_name === 'post_likes'){
    	$likes = '';
    	$likes = get_post_meta( get_the_id(), "_post_like_count", true );
    	if( 0 < $likes ){
    		echo esc_html( $likes );;
    	} else {
    		echo esc_html( '0' );
    	}
    }
}


/**
 * Render POST NAVIGATOR
 * @since wishbone 1.0
 */
function wishbone_post_navigation(){ ?>

	<?php
	$prev_link = $next_link = '';
	$prev_link = get_previous_posts_link(__('&laquo; Older Entries', 'jt-wishbone'));
	$next_link = get_next_posts_link(__('Newer Entries &raquo;', 'jt-wishbone'));
	if ($prev_link || $next_link) {
	 ?>
	<!-- Post Loop Navigation -->
	<div class="wishbone_postnav">
		<div class="large-6 column">
			<?php next_posts_link( esc_html__('PREVIOUS POSTS', 'jt-wishbone') ); ?>
		</div>
		<div class="large-6 column">
			<?php previous_posts_link( esc_html__('NEXT POSTS', 'jt-wishbone') ); ?>
		</div>
		<div class="clear"></div>
	</div>
	<?php } ?>
<?php
}

/**
 * Render Author Info under post article
 * @since wishbone 1.0
 */
function wishbone_post_author(){ ?>
	<div class="wishbone_authorinfo_container">
		<div class="wishbone_authorinfo_box">
			<div class="row">
				<div class="small-2 columns">
					<div class="authorava">
						<?php echo get_avatar( get_the_author_meta('email') , 100 ); ?>
					</div>
				</div>
				<div class="small-10 columns">
					<div class="author_desc">
						<strong class="ain"><?php the_author_posts_link(); ?></strong>
						<p><?php  echo get_the_author_meta('description'); ?></p>
						<div class="clear"></div>
						<ul class="author_social text-center">
						<?php
							$rss_url = get_the_author_meta( 'rss_url' );
							if ( $rss_url && $rss_url != '' ) {
								echo '<li class="rss"><a href="' . esc_url($rss_url) . '"><i class="icon-rss"></i></li>';
							}

							$google_profile = get_the_author_meta( 'google_profile' );
							if ( $google_profile && $google_profile != '' ) {
								echo '<li class="google"><a href="' . esc_url($google_profile) . '" rel="author"><i class="icon-gplus"></i></a></li>';
							}

							$twitter_profile = get_the_author_meta( 'twitter_profile' );
							if ( $twitter_profile && $twitter_profile != '' ) {
								echo '<li class="twitter"><a href="' . esc_url($twitter_profile) . '"><i class="icon-twitter"></i></a></li>';
							}

							$facebook_profile = get_the_author_meta( 'facebook_profile' );
							if ( $facebook_profile && $facebook_profile != '' ) {
								echo '<li class="facebook"><a href="' . esc_url($facebook_profile) . '"><i class="icon-facebook"></i></a></li>';
							}

							$linkedin_profile = get_the_author_meta( 'linkedin_profile' );
							if ( $linkedin_profile && $linkedin_profile != '' ) {
								   echo '<li class="linkedin"><a href="' . esc_url($linkedin_profile) . '"><i class="icon-linkedin"></i></a></li>';
							}
						?>
						</ul>
					</div>
				</div>
				<div class="clear"></div>
			</div>
		</div>
	</div>
<?php

}


/**
 * Render Related Posts
 * @since wishbone 1.0
 */
function wishbone_related_posts( $postid ){

    $tags = $cats = '';
    $tags = wp_get_post_tags( $postid );
    $cats = wp_get_post_categories( $postid );
    if( $tags or $cats ) {

		$tag_ids = array();
		$cat_ids = array();

		foreach( $tags as $individual_tag ) $tag_ids[] = $individual_tag->term_id;
		foreach( $cats as $individual_cat ) $cat_ids[] = $individual_cat;

		$args = array(
			'post_status' => 'publish',
			'post__not_in' => array( $postid ),
			'posts_per_page'=> 3,
			'ignore_sticky_posts'=> 1,
			'orderby'=> 'rand',
			'meta_query' => array(array('key' => '_thumbnail_id'))
		);

		if( $tag_ids ){
			$args = array_merge( $args, array( 'tag__in' => $tag_ids, ) );
		} else {
			// If the post doesn't have any tag, use category
			if( $cat_ids ){
				$args = array_merge( $args, array( "category__in" => $cat_ids, ) );
			}
		}

		// Set post queries
		$related_posts = new WP_Query( $args );

        if( $related_posts->have_posts() ){
        	echo '<div class="wishbone_post_extra">';
		    echo '<div class="wishbone_related_posts">';
		    echo '<h3>'. lnr_icon_raw('lnr-layers').' '.esc_html__('You Might Also Like', 'jt-wishbone') .'</h3>';
        	echo '<div id="wishbone_related-posts" class="row">';
        	echo '<div class="row">';

        		while( $related_posts->have_posts() ){
        			$related_posts->the_post(); ?>
        			<div class="related_post large-4 medium-4 small-12 column">
	        			<div class="wishbone_relatedinner">
	                		<?php
	                			if( has_post_thumbnail() ){
	                				echo '<div class="wishbone_related_thumb">';
	                				echo '<a href="'. esc_url( get_permalink() ) .'">';
	                				the_post_thumbnail( 'medium' );
	                				echo '</a>';
	                				echo '</div> <!-- end .wishbone_related_thumb -->';
	                			}
	                		?>
		                    <div class="wishbone_relate_cat">
		                    	<?php the_category(', '); ?>
		                    </div>
		                    <a class="entry-unrelated" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
		                    <div class="clear"></div>
		                </div> <!-- end of .related_post -->
	                </div> <!-- end of .related_post -->
        		<?php
        		}
        		wp_reset_postdata();

        	echo '</div>'; // .row;
       		echo '</div>'; // #wishbone_related-posts.row;
       		echo '</div>'; // .wishbone_related_posts
			echo '</div>'; // .wishbone_post_extra

        }

    }
}


/**
* Render Social Icons
*/
function social_icons(){
	$social_label = $social_icons = '';
	$social_label = wishbone_option('social_label');
	$social_icons = wishbone_option('social_icons', '');
	if( !empty( $social_icons ) ){
		foreach( $social_icons as $icon ){
			echo '<li><a href="'. esc_url( $icon['social_url'] ) .'" title="'. esc_attr($icon['social_name'] ) .'"><span class="'. esc_attr( $icon['social_icon'] ) .'"></span></a></li>'."\n";
		}
	} else { ?>
		<li><a href="#"><span class="icon-facebook"></span></a></li>
		<li><a href="#"><span class="icon-twitter"></span></a></li>
		<li><a href="#"><span class="icon-youtube"></span></a></li>
		<li><a href="#"><span class="icon-linkedin"></span></a></li>
		<li><a href="#"><span class="icon-dribbble"></span></a></li>
	<?php
	}
}

/**
 * Set up the Breadcrumb
 *
 * @since wishbone 1.0
 */
function wishbone_breadcrumbs() {
	if(!is_home() or !is_front_page()){
		echo '<div class="wishbone_breadcrumbs" id="breadcrumb">';
		echo '<div class="row">';
		echo '<div class="large-12 column">';
		echo '<ul class="breadcrumb_list">';
		echo '<li><a href="';
		echo esc_url( home_url('/') );
		echo '">';
		echo '<svg class="lnr lnr-home"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="'.get_template_directory_uri().'/assets/svg/svgdefs.svg#lnr-home"></use></svg>';

		echo "</a></li>".'<li class="wishbone_bc_delimieter"><svg class="lnr lnr-chevron-right"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="'.get_template_directory_uri().'/assets/svg/svgdefs.svg#lnr-chevron-right"></use></svg></li>';
	}
	if ( is_singular() ) {
		if (is_category() || is_single()) {
			echo '<li>';
			the_category(', </li><li> ');
			if ( is_single() ) {
				echo "</li>".'<li class="wishbone_bc_delimieter"><svg class="lnr lnr-chevron-right"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="'.get_template_directory_uri().'/assets/svg/svgdefs.svg#lnr-chevron-right"></use></svg></li>'."<li class='current'>";
				the_title();
				echo '</li>';
			}
		} elseif (is_page()) {
			echo '<li class="current">';
			echo the_title();
			echo '</li>';
		}
	}
	elseif (is_tag()) {
		echo "<li class='current'>".esc_html__('Tag: ', 'jt-wishbone');
		single_tag_title();
		echo "</li>";
	}

	elseif (is_day()) { echo "<li class='current'>Archive for "; the_time('F jS, Y'); echo'</li>';}

	elseif (is_month()) { echo "<li class='current'>Archive for "; the_time('F, Y'); echo'</li>';}

	elseif (is_year()) { echo "<li class='current'>Archive for "; the_time('Y'); echo'</li>';}

	elseif (is_author()) { echo "<li class='current'>Author Archive"; echo'</li>';}

	elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { echo "<li class='current'>Blog Archives"; echo'</li>';}

	elseif (is_search()) { echo "<li class='current'>Search Results"; echo'</li>';}

	elseif ( is_category() ){
		echo '<li class="current">'.esc_html__('Category: ', 'jt-wishbone');
		single_cat_title();
		echo "</li>";
	}

	elseif( is_404() ){
		echo '<li class="current">';
		echo esc_html__('404', 'jt-wishbone');
		echo '</li>';
	}

	if(!is_home() or !is_front_page()){
		echo '</ul>';
		echo '</div>';
		echo '</div>';
		echo '</div>';
	}

}

/**
 * HEADER 1
 * @since wishbone 1.0
 */
function wishbone_header_1(){ ?>

	<!-- HEADER 1 -->
	<div class="wishbone_header_1 show-for-medium-up">
		<!-- Topbar -->
		<div class="wishbone_topbar">
			<div class="row">
				<div class="medium-6 column">
					<ul class="wishbone_social">
						<?php social_icons(); ?>
					</ul>
				</div>
				<div class="medium-6 column">
					<div class="wishbone_searchform">
						<?php
							get_search_form(); 
						?>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>

		<!-- Header -->
		<div id="wishbone_mainheader">
			<div class="row stickytarget">
				<div class="medium-4 column hide-for-portrait">
					<?php
						wp_nav_menu( array( 'menu_class' => 'wishbone_mainmenu text-right zlleftmenu', 'theme_location' => 'primary', 'container' => false, 'fallback_cb'=> 'wishbone_fallbackmenu', 'walker' => new zl_mega_menu_walker() ) );
					 ?>
				</div>
				<div class="large-4 medium-12 column text-center brand">
					<?php
						$logo = wishbone_option('logo');
						$logo_retina = wishbone_option('logo_retina');
						#print_r($logo);
						if( !empty($logo) ) {
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
							echo '</a>';
						} else {
							echo '<h1 class="wishbone_logo_text">';
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo get_bloginfo( 'name' );
							echo '</a>';
							echo '</h1>';
						}
						 ?>
				</div>
				<div class="medium-4 column hide-for-portrait">
					<ul class="wishbone_mainmenu text-left zlrightmenu"></ul>
				</div>
				<div class="clear"></div>
				<ul class="wishbone_mainmenu wishbone_header1menualt text-center hide-for-medium-up show-for-portrait">
					<?php wp_nav_menu( array( 'container'=> false, 'items_wrap' => '%3$s', 'theme_location' => 'primary', 'fallback_cb'=> 'wishbone_fallbackmenu') ); ?>
				</ul>
			</div>
		</div>

	</div>

<?php
}

/**
 * HEADER 2
 * @since wishbone 1.0
 */
function wishbone_header_2(){ ?>
	<!-- Topbar -->
	<div class="wishbone_header_2 show-for-medium-up">
		<div class="wishbone_topbar">
			<div class="row">
				<div class="medium-6 large-8 column">
					<ul class="wishbone_social">
						<?php social_icons(); ?>
					</ul>
				</div>
				<div class="medium-6 large-4 column">
					<div class="wishbone_searchform">
						<?php
							get_search_form( true ); 
						?>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>

		<!-- Header -->
		<div id="wishbone_mainheader">
			<div class="row stickytarget">
				<div class="large-3 column text-left medium-text-center brand">
					<?php
						$logo = wishbone_option('logo');
						$logo_retina = wishbone_option('logo_retina');
						#print_r($logo);
						if( !empty($logo) ) {
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
							echo '</a>';
						} else {
							echo '<h1 class="wishbone_logo_text">';
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo get_bloginfo( 'name' );
							echo '</a>';
							echo '</h1>';
						}
						 ?>
				</div>
				<div class="large-9 medium-12 column">
					<?php
						wp_nav_menu( array( 'menu_class' => 'wishbone_mainmenu text-right medium-text-center', 'theme_location' => 'primary', 'container' => false, 'fallback_cb'=> 'wishbone_fallbackmenu', 'walker' => new zl_mega_menu_walker() ) );
					 ?>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
<?php
}

/**
 * HEADER 3
 * @since wishbone 1.0
 */
function wishbone_header_3(){ ?>
	<!-- Topbar -->
	<div class="wishbone_header_3 show-for-medium-up">
		<div class="wishbone_topbar">
			<div class="row">
				<div class="large-8 medium-6 column">
					<ul class="wishbone_social">
						<?php social_icons(); ?>
					</ul>
				</div>
				<div class="large-4 medium-6 column">
					<div class="wishbone_searchform">
						<?php
							get_search_form( true ); 
						?>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>

		<!-- Header -->
		<div id="wishbone_mainheader">
			<div class="row">
				<div class="large-12 column text-center brand">
					<?php
						$logo = wishbone_option('logo');
						$logo_retina = wishbone_option('logo_retina');
						#print_r($logo);
						if( !empty($logo) ) {
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
							echo '</a>';
						} else {
							echo '<h1 class="wishbone_logo_text">';
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo get_bloginfo( 'name' );
							echo '</a>';
							echo '</h1>';
						}
						 ?>
				</div>
				<div class="large-12 column">
					<?php
						wp_nav_menu( array( 'menu_class' => 'wishbone_mainmenu text-center stickytarget', 'theme_location' => 'primary', 'container' => false, 'fallback_cb'=> 'wishbone_fallbackmenu', 'walker' => new zl_mega_menu_walker() ) );
					 ?>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
<?php
}

/**
 * HEADER 4
 * @since wishbone 1.0
 */
function wishbone_header_4(){ ?>
	<!-- Topbar -->
	<div class="wishbone_header_4 show-for-medium-up">
		<!-- Header -->
		<div id="wishbone_mainheader">
			<div class="wishbone_bartop">
				<div class="row stickytarget">
					<div class="large-12 column">
						<?php
							wp_nav_menu( array( 'menu_class' => 'wishbone_mainmenu text-center', 'theme_location' => 'primary', 'container' => false, 'fallback_cb'=> 'wishbone_fallbackmenu', 'walker' => new zl_mega_menu_walker() ) );
						 ?>
					</div>
				</div>
			</div>
			<div class="row wishbone_header_4_subheader">
				<div class="large-4 column">
					<ul class="wishbone_social medium-text-center">
						<?php social_icons(); ?>
					</ul>
				</div>
				<div class="large-4 column text-center brand">
					<?php
						$logo = wishbone_option('logo');
						$logo_retina = wishbone_option('logo_retina');
						#print_r($logo);
						if( !empty($logo) ) {
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
							echo '</a>';
						} else {
							echo '<h1 class="wishbone_logo_text">';
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo get_bloginfo( 'name' );
							echo '</a>';
							echo '</h1>';
						}
						 ?>
				</div>
				<div class="large-4 column">
					<div class="wishbone_searchform">
						<?php
							get_search_form( true ); 
						?>
					</div>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
<?php
}

/**
 * HEADER 5
 * @since wishbone 1.0
 */
function wishbone_header_5(){ ?>
	<!-- Topbar -->
	<div class="wishbone_header_5 show-for-medium-up">
		<!-- Header -->
		<div id="wishbone_mainheader">
			<div class="wishbone_bartop">
				<div class="row stickytarget">
					<div class="large-9 column">
						<?php
							wp_nav_menu( array( 'menu_class' => 'wishbone_mainmenu text-left', 'theme_location' => 'primary', 'container' => false, 'fallback_cb'=> 'wishbone_fallbackmenu', 'walker' => new zl_mega_menu_walker() ) );
						 ?>
					</div>
					<div class="large-3 column">
						<ul class="wishbone_social right">
							<?php social_icons(); ?>
						</ul>
					</div>
				</div>
			</div>
			<div class="row wishbone_header_4_subheader">
				<div class="large-4 medium-6 column text-left brand">
					<?php
						$logo = wishbone_option('logo');
						$logo_retina = wishbone_option('logo_retina');
						#print_r($logo);
						if( !empty($logo) ) {
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
							echo '</a>';
						} else {
							echo '<h1 class="wishbone_logo_text">';
							echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
							echo get_bloginfo( 'name' );
							echo '</a>';
							echo '</h1>';
						}
						 ?>
				</div>
				<div class="large-8 medium-6 column">
					<div class="wishbone_searchform">
						<?php
							get_search_form( true ); 
						?>
					</div>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
<?php
}

/**
* MOBILE HEADER
*/
function wishbone_mobileheader() { ?>
	<div class="wishbone_m_header hide-for-medium-up">
		<!-- Top Bar -->
		<div class="wishbone_m_topbar">
			<div class="row wishbone_topbarcontainer">
				<div class="small-2 column">
					<div class="wishbone_m_menutrigger">
						<?php lnr_icon('lnr-menu'); ?>
					</div>
				</div>
				<div class="small-10 column">
					<ul class="wishbone_social right">
						<?php social_icons(); ?>
						<li>
							<a href="#" class="wishbone_m_srctrigger">
								<?php lnr_icon('lnr-magnifier'); ?>
							</a>
						</li>
					</ul>
				</div>

				<!-- Mobile Search -->
				<div class="wishbone_m_searchwrapper">
					<?php get_search_form(); ?>
				</div>
				<!-- Mobile Menu -->
				<div class="wishbone_m_menu_wrapper">
					<ul class="wishbone_m_menuitems">
						<?php wp_nav_menu( array( 'container'=> false, 'items_wrap' => '%3$s', 'theme_location' => 'primary', 'fallback_cb'=> 'wishbone_fallbackmenu') ); ?>
					</ul>
				</div>
			</div>
		</div>

		<!-- Branding logo mobile -->
		<div class="wishbone_m_branding">
			<?php
				$logo = wishbone_option('logo');
				$logo_retina = wishbone_option('logo_retina');
				#print_r($logo);
				if( !empty($logo) ) {
					echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
					echo '<img src="'.esc_attr( $logo['url'] ).'" alt="'.get_bloginfo( 'name' ).'" data-at2x="'.esc_attr( $logo_retina['url'] ).'"/>';
					echo '</a>';
				} else {
					echo '<h1 class="wishbone_logo_text">';
					echo '<a href="'.esc_url( esc_url( home_url('/') ) ).'">';
					echo get_bloginfo( 'name' );
					echo '</a>';
					echo '</h1>';
				}
			 ?>
		</div>
	</div>
<?php
}

/**
* STICKY MENU
*/
function wishbone_stickymenu(){ ?>
	<div class="wishbone_sticky_menu">
		<ul class="stickymenuitems">
			<?php wp_nav_menu( array( 'container'=> false, 'items_wrap' => '%3$s', 'theme_location' => 'primary', 'fallback_cb'=> 'wishbone_fallbackmenu') ); ?>
		</ul>
	</div>
<?php
}

/**
* Render Footer Content
* @var $sections
*/
function wishbone_footer_content(){
	$sections = '';
	$sections = wishbone_option('footer_section');

	if(!empty($sections)){
		foreach ($sections as $section) {
			/* Empty value to prevent error */
	        $section_name = $footer_widget = $sec_type = $sec_vertical_padding = $sec_vertical_margin = $sec_background_clr = $sec_text_clr = $sec_brd_clr = '';
			/*Get all variables*/
			$section_name 			= $section['section_name'];
			$footer_widgets  		= $section['footer_widgets'];
			$sec_type 				= $section['sec_type'];
			$sec_vertical_padding 	= $section['sec_vertical_padding'];
			$sec_vertical_margin 	= $section['sec_vertical_margin'];
			$sec_background_clr 	= $section['sec_background_clr'];
			$sec_brd_clr 			= $section['sec_brd_clr'];
			$sec_text_clr 			= $section['sec_text_clr'];



			if($section_name){
				$sec_class = '';
				if($sec_background_clr || $sec_brd_clr || $sec_text_clr || $sec_vertical_padding || $sec_vertical_margin){
					$sec_bg = $sec_pad = $sec_mar = $sec_text = $sec_brd = '';
					$sec_bg = 'background-color: '.$sec_background_clr.';';
					$sec_brd = ( !empty($sec_brd_clr) ) ? 'border-top: 1px solid '.$sec_brd_clr.';' : '' ;
					$sec_pad = 'padding: '.$sec_vertical_padding.'px 0'.';';
					$sec_mar = 'margin: '.$sec_vertical_margin.'px 0'.';';
					$sectionstyle = "style='{$sec_bg} {$sec_pad} {$sec_mar} {$sec_brd}'";
				}
				$section_id = strtolower( str_replace( ' ', '-', $section_name ) );
				echo '<!-- Start of '.esc_html( $section_name ).'-->'."\n";
				echo '<div '.wp_kses( $sectionstyle, null, null ).' class="foo_section '.esc_attr( $section_id.' '.$sec_text_clr.' '.$sec_type ).'" id="'.esc_attr( $section_id ).'">'."\n";


					/* <div class="row"> */
					if( 'boxed' == $sec_type ){	echo '<div class="row">'."\n"; }


							/* Footer Widgets */
							if(!empty($footer_widgets)){
								foreach ($footer_widgets as $footer_widget) {

									/* Prevent Error */
									$footer_widget_name = $column_width = '';

									/* Define Variables */
									$footer_widget_name = $footer_widget['footer_widget_name'];
									$column_width = $footer_widget['column_width'];
									// $column_width = str_replace('large', 'medium', $column_width);
									$column_width = $column_width;

									if($column_width){
										echo '<div class="'.esc_attr( $column_width ).' wishbone_footerwidgetarea">';

											if ( function_exists('dynamic_sidebar') && dynamic_sidebar(strtolower(str_replace(' ', '-', $footer_widget_name))) ) : else : endif;

										echo '</div>';
									}
								}
							}


					/* </div> */
					if( 'boxed' == $sec_type ){	echo '</div><div class="clear"></div>'."\n"; }


				echo '</div><!-- end of '.esc_html($section_name).'-->'."\n";
			}
		}
	}
}

/**
 * Render NUMERIC PAGINATION
 * @since wishbone 1.0
 */
function wishbone_numeric_paging( $pages = '', $range = 3 ){
	$showitems = ($range * 2)+1;

	global $paged;
	if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }

   if($pages == '')
    {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
    }

     if(1 != $pages)
     {
        echo "<!-- pagination -->\n";
        echo "<ul class='wishbone_paging'>\n";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo;</a></li>";
         if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a></li>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li><a href='#' class='current'>".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a></li>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>&raquo;</a></li>";
         echo "</ul>\n";
     }
}

/**
 * Pagination RENDER for THIS THEME ONLY
 * @since wishbone 1.0
 */
function wishbone_pagination($pages=''){
    global $post;


    if( is_page_template( 'template-home.php' ) ){
		$pages = $pages;
	} else {
		if($pages == '')
	    {
	         global $wp_query;
	         $pages = $wp_query->max_num_pages;
	         if(!$pages)
	         {
	             $pages = 1;
	         }
	    }
	}

    if(1 != $pages) { ?>
	    <!-- ooooooooooooooooo
	        PAGINATION
	    oooooooooooooooooo -->
	    <div class="wishbone_pagination" <?php echo esc_attr( $pages ); ?>>
	        <?php if(function_exists('wishbone_numeric_paging')) wishbone_numeric_paging($pages); ?>
	    	<div class="clear"></div>
	    </div>
	<?php
    }
}

/**
 * Render POST NAVIGATOR
 * @since airashi 1.0
 */
function wishbone_nextprev_pagination( $max_pages = null ){ ?>

	<?php
	if( $max_pages ){
		$pages = $max_pages;
	} else {
		$pages = null;
	}

	 ?>

	<!-- PAGINATION -->
	<div class="wishbone_pagination nextprev row">
		<div class="medium-6 column wishbone_prev">
			<?php next_posts_link( esc_html__('Older Entries', 'jt-wishbone'), $pages ); ?>
		</div>
		<div class="medium-6 column wishbone_next">
			<?php previous_posts_link( esc_html__('Newer Entries', 'jt-wishbone') ); ?>
		</div>
		<div class="clear"></div>
	</div>
	<?php
}

// LOAD MORE DATA
add_action( 'wp_ajax_wishbone_loadmore', 'wishbone_loadmore' );
add_action( 'wp_ajax_nopriv_wishbone_loadmore', 'wishbone_loadmore' );
if(!function_exists('wishbone_loadmore')){
	function wishbone_loadmore() {

		// Set variables
		$looptype = $_POST['looptype'];
		$perpage = $_POST['perpage'];
		$targetpaged = $_POST['currentpaged'] + 1;

		$args = array(
			'post_type' => 'post',
			'post_status' => 'publish',
			'posts_per_page' => $perpage,
			'ignore_sticky_posts' => 1,
			'paged' => $targetpaged,
		);

		// Category
		if( isset($_POST['cat']) ){
			$cat = $_POST['cat'];
			$args = array_merge( $args, array( "cat" => $cat ) );
		}

		// Year
		if( isset( $_POST['year'] ) ){
			$year = $_POST['year'];
			$args = array_merge( $args, array( "year" => $year ) );
		}

		// Month
		if( isset( $_POST['month'] ) ){
			$month = $_POST['month'];
			$args = array_merge( $args, array( "monthnum" => $month ) );
		}

		// Day
		if( isset( $_POST['day'] ) ){
			$day = $_POST['day'];
			$args = array_merge( $args, array( "day" => $day ) );
		}

		// Author
		if( isset( $_POST['author'] ) ){
			$author = $_POST['author'];
			$args = array_merge( $args, array( "author" => $author ) );
		}

		// Search
		if( isset( $_POST['search'] ) ){
			$search = $_POST['search'];
			$args = array_merge( $args, array( "s" => $search ) );
		}

		// Tag
		if( isset( $_POST['tag_id'] ) ){
			$tag_id = $_POST['tag_id'];
			$args = array_merge( $args, array( "tag_id" => $tag_id ) );
		}


		$ajaxresults = new WP_Query( $args );

		ob_start();
		if( $ajaxresults->have_posts() ):
			while( $ajaxresults->have_posts() ): $ajaxresults->the_post();
				get_template_part('loop', $looptype);
			endwhile;
			wp_reset_postdata();
		endif;
		$html = ob_get_clean();

		$response = array(
	        'sucess' => true,
	        'html' => $html ,
	    );

	    // generate the response
	    print json_encode($response);
	    // IMPORTANT: don't forget to "exit"
	    exit;
	}
}


/**
 * Render Ajax Pagination (Load More)
 * @since wishbone 1.0
 */
function wishbone_ajax_pagination( $looptype = null, $post=null ){
	global $wp_query;
	global $paged;
	$search = $author = $datayear = $datamonth = $dataday = $dataauthor = $datasearch = $datatag = $tag = '';
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

	if( is_page_template( 'template-home.php' ) ){
		$maxpages = $post;
	} else {
		$maxpages = $wp_query->max_num_pages;
	}


	/*'day' => $currentday, //tanggal
	'year' => $currentyear, //tahun
	'monthnum' => $currentmonth, //bulan*/


	//Category
	if( is_category() ){
		$cat_id = 'data-cat="'.get_query_var('cat').'"';
	} else {
		$cat_id = null;
	}

	//Archive
	if( is_archive() ){

		$year = get_the_time('Y');
		$month = get_the_time('m');
		$day = get_the_time('j');

		if( is_year() ){
			$datayear = 'data-year="'.$year.'"';
		} elseif( is_month() ) {
			$datayear = 'data-year="'.$year.'"';
			$datamonth = 'data-month="'.$month.'"';
		} elseif( is_day() ) {
			$datayear = 'data-year="'.$year.'"';
			$datamonth = 'data-month="'.$month.'"';
			$dataday = 'data-day="'.$day.'"';
		}

	}

	// Author
	if( is_author() ){
		$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
		$dataauthor = 'data-author="'.$author->ID.'"';
	}

	// Search
	if( is_search() ){
		$search = get_search_query();
		$datasearch = 'data-search="'.$search.'"';
	}

	// Tag
	if( is_tag() ){
		$tag = get_query_var('tag_id');
		$datatag = 'data-tag="'.$tag.'"';
	}

	if( $paged != $maxpages ) {
	?>
		<a href="#" class="wishbone_loadmorebutton"
		data-looptype="<?php echo esc_attr( $looptype ); ?>"
		data-perpage="<?php echo esc_attr( get_option('posts_per_page') ); ?>"
		data-currentpaged="<?php echo esc_attr( $paged ); ?>"
		data-maxpages="<?php echo esc_attr( $maxpages );  ?>"
		<?php echo wishbone_pass_html( $cat_id.' '.$datayear.' '.$datamonth.' '.$dataday.' '.$dataauthor.' '.$datasearch.' '.$datatag ); ?>>
			<?php esc_html_e( 'LOAD MORE', 'jt-wishbone' ); ?>
		</a>
	<?php
	}
}

/*
 * Loop Type
 */
function wishbone_looptype( $type = null ){
	$postlayout = $type;
	if( 'masonry' == $postlayout ){
		echo '<div class="wishbone_msn_posts">';
		echo '<div class="grid-sizer"></div>';
			while( have_posts() ): the_post();
				get_template_part('loop', $postlayout);
			endwhile;
		echo '</div>';
	} elseif( 'simplegrid' == $postlayout ) {
		echo '<div class="wishbone_simgrid_posts">';
		echo '<div class="grid-sizer"></div>';
			while( have_posts() ): the_post();
				get_template_part('loop', $postlayout);
			endwhile;
		echo '</div>';
	} elseif( 'simplelist' == $postlayout ) {
		while( have_posts() ): the_post();
			get_template_part('loop', $postlayout);
		endwhile;
	} elseif( 'classic' == $postlayout ) {
		while( have_posts() ): the_post();
			get_template_part('loop', $postlayout);
		endwhile;
	} else {
		while( have_posts() ): the_post();
			get_template_part('loop', $postlayout);
		endwhile;
	}
}

/*
 * Pagination Type
 */
function wishbone_paging_type( $type = null, $postlayout = null ){

	if( 'loadmore' == $type ){
		wishbone_ajax_pagination( $postlayout );
	} elseif( 'nextprev' == $type ){
		wishbone_nextprev_pagination();
	} else {
		wishbone_pagination();
	}

}

/**
 * Render POST NAVIGATOR
 * @since airashi 1.0
 */
function wishbone_postnavigator(){
	global $post;
	$prev = get_adjacent_post(false, '', true);
	$next = get_adjacent_post(false, '', false);
	if ( !empty( $prev ) ) {
		$prevID = $prev->ID;
	}
	if ( !empty( $next ) ) {
		$newerID = $next->ID;
	}
	?>

	<!-- ooooooooooooooooo
		POST NAVIGATOR
	oooooooooooooooooo -->
	<div class="clear"></div>
	<div class="wishbone_single_postnav">
		<div class="wishbone_single_postnav_inner">
				<?php
					if($prev) {
						$url = get_permalink($prev->ID);
					?>
						<div class="wishbone_postnavitem">
							<div class="wishbone_postnavthumb">
								<a href="<?php echo get_the_permalink( $prev->ID ) ?>">
								<?php
									if( has_post_thumbnail( $prev->ID ) ){
										echo get_the_post_thumbnail( $prev->ID, 'wishbone_eighty' );
									}
								 ?>
								 </a>
							</div>
							<div class="wishbone_postnavtitle">
								<?php esc_html_e('PREVIOUS POST', 'jt-wishbone') ?>
								<a href="<?php echo get_the_permalink( $prev->ID ) ?>">
									<?php echo get_the_title( $prev->ID ) ?>
								</a>
							</div>
							<div class="clear"></div>
						</div>
					<?php
					}

					if($next){
						$url = get_permalink($next->ID);
					?>
						<div class="wishbone_postnavitem zlpninext">
							<div class="wishbone_postnavthumb">
								<a href="<?php echo get_the_permalink( $next->ID ) ?>">
								<?php
									if( has_post_thumbnail( $next->ID ) ){
										echo get_the_post_thumbnail( $next->ID, 'wishbone_eighty' );
									}
								 ?>
								</a>
							</div>
							<div class="wishbone_postnavtitle">
								<?php esc_html_e('NEWER POST', 'jt-wishbone') ?>
								<a href="<?php echo get_the_permalink( $next->ID ) ?>">
									<?php echo get_the_title( $next->ID ) ?>
								</a>
							</div>
							<div class="clear"></div>
						</div>
					<?php
					}
				?>
		</div>
		<div class="clear"></div>
	</div>
	<div class="clear"></div>
	<?php
}

/**
 * Generate ARTICLE BOTTOM
 * @since airashi 1.0
 */
function wishbone_articlebottom(){
	global $post;

	$postsharing = wishbone_option('postsharing');
	$authorinfo = wishbone_option('authorinfo');

	?>
	<div class="wishbone_articlebottom hide-for-small-down">
		<div class="wishbone_articlefooter">
			<?php
			if( function_exists('wishbone_sharecount') && true == $postsharing ){
				$tagcol = 'large-9 medium-8 small-12';
			} else {
				$tagcol = 'large-12';
			} ?>
			<div class="<?php echo esc_attr( $tagcol ); ?> column">
				<div class="wishbone_tags">
					<?php the_tags( lnr_icon('lnr-tag').'', ' ', null ); ?>
				</div>
			</div>
			<?php
			if( function_exists('wishbone_sharecount') && true == $postsharing ){
			 ?>
				<div class="large-3 medium-4 small-12 column wishbone_shortlink">
					<div class="wishbone_totalshare">
						<?php echo lnr_icon_raw('lnr-earth').' '; ?>
						<?php
							echo wishbone_sharecount( get_permalink() ) . ' <span>'. esc_html__( 'Shares', 'jt-wishbone' ).'</span>';
						 ?>
					</div>
				</div>
			<?php } ?>
			<div class="clear"></div>

			<!-- Share -->
			<?php if( true == $postsharing ): ?>
			<div class="wishbone_articlefootershare">
				<?php
				$social_share = wishbone_option('social_share');
				$thumb = get_post_thumbnail_id();
				$img_url = wp_get_attachment_url( $thumb );
				 ?>
				<div class="large-12 column">
					<?php lnr_icon('lnr-exit-up'); ?>
					<a href="#" data-type="facebook" data-url="<?php the_permalink(); ?>" data-title="<?php the_permalink(); ?>" data-description="<?php echo get_the_excerpt(); ?>" data-media="<?php echo esc_attr($img_url); ?>" class="prettySocial facebook">
						<span class="icon-facebook"></span> <?php esc_html_e('Share', 'jt-wishbone') ?>
					</a>
					<a href="#" data-type="twitter" data-url="<?php the_permalink(); ?>" data-description="<?php echo substr(get_the_title(), 0,140); ?>" class="prettySocial twitter">
						<span class="icon-twitter"></span> <?php esc_html_e('Tweet', 'jt-wishbone') ?>
					</a>
					<a href="#" data-type="pinterest" data-url="<?php the_permalink(); ?>" data-description="<?php echo get_the_excerpt(); ?>" data-media="<?php echo esc_attr($img_url); ?>" class="prettySocial pinterest">
						<span class="icon-pinterest"></span> <?php esc_html_e('Pin It', 'jt-wishbone') ?>
					</a>
					<a href="#" data-type="googleplus" data-url="<?php the_permalink(); ?>" data-description="<?php echo get_the_excerpt(); ?>" class="prettySocial gplus">
						<span class="icon-gplus"></span> <?php esc_html_e('Share', 'jt-wishbone') ?>
					</a>
					<a href="#" data-type="linkedin" data-url="<?php the_permalink(); ?>" data-title="<?php the_permalink(); ?>" data-description="<?php echo get_the_excerpt(); ?>" data-media="<?php echo esc_attr($img_url); ?>" class="prettySocial linkedin">
						<span class="icon-linkedin"></span> <?php esc_html_e('LinkedIn', 'jt-wishbone') ?>
					</a>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
				
			</div>
			<div class="clear"></div>
			<?php endif; ?>

			<?php if( true == $postsharing ): ?>
			<!-- Author -->
			<div class="wishbone_articleauthorinfo">
				<div class="large-2 small-2 column">
					<div class="wishbone_authorwriterava">
						<?php echo get_avatar( get_the_author_meta('email') , 100 ); ?>
					</div>
				</div>
				<div class="large-10 small-10 column">
					<strong class="ain"><?php the_author_posts_link(); ?></strong>
					<p>
						<?php
							if( get_the_author_meta('description') ){
								echo get_the_author_meta('description');
							} else {
								esc_html_e('This author is too shy to write description', 'jt-wishbone');
							}
						?>
					</p>
					<ul class="wishbone_author_social">
						<?php
							$rss_url = get_the_author_meta( 'rss_url' );
							if ( $rss_url && $rss_url != '' ) {
								echo '<li class="rss"><a href="' . esc_url($rss_url) . '"><i class="icon-rss"></i></li>';
							}

							$google_profile = get_the_author_meta( 'google_profile' );
							if ( $google_profile && $google_profile != '' ) {
								echo '<li class="google"><a href="' . esc_url($google_profile) . '" rel="author"><i class="icon-gplus"></i></a></li>';
							}

							$twitter_profile = get_the_author_meta( 'twitter_profile' );
							if ( $twitter_profile && $twitter_profile != '' ) {
								echo '<li class="twitter"><a href="' . esc_url($twitter_profile) . '"><i class="icon-twitter"></i></a></li>';
							}

							$facebook_profile = get_the_author_meta( 'facebook_profile' );
							if ( $facebook_profile && $facebook_profile != '' ) {
								echo '<li class="facebook"><a href="' . esc_url($facebook_profile) . '"><i class="icon-facebook"></i></a></li>';
							}

							$linkedin_profile = get_the_author_meta( 'linkedin_profile' );
							if ( $linkedin_profile && $linkedin_profile != '' ) {
								   echo '<li class="linkedin"><a href="' . esc_url($linkedin_profile) . '"><i class="icon-linkedin"></i></a></li>';
							}
						?>
					</ul>
				</div>
				<div class="clear"></div>
			</div>
			<?php endif; ?>
			<div class="clear"></div>
		</div>
	</div>
<?php
}
