﻿<?php
/**
  Template Name: Blog Template
 */
get_header();
$redirectedlink = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>
<!-- blog -->
<div class="bloc tc-outer-space bgc-white-smoke l-bloc b-divider" id="blog">
	<div class="container bloc-lg">
		<div class="row">
			<div class="col-sm-12">
				<h1 class="text-center mg-md drag-obj animated sm-shadow fadeInUp">
					<a href="<?php echo esc_url( home_url('/') ); ?>/blog">Blog</a>
				</h1>
				<p class="text-center sub-heading mg-lg  sm-shadow animated animDelay02 fadeInUp">
					Just a sample of BLOG.
				</p>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-8">	
				<a name="blog1"></a>
				<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
				<div class="panel panel-sq">
					<div class="panel-body">
						<h4 class="mg-md ">
							<span class="ion ion-clock animated fadeIn"> <?php the_time('Fj日Y年'); ?> <?php //the_time('F jS Y'); ?></span>
						</h4>
						<h3 class="mg-md animated fadeIn">
							<strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong>
						</h3>
						<div class="divider-h">
							<span class="divider"></span>
						</div>
						<a href="<?php the_permalink(); ?>" class="fullthubimg"><?php the_post_thumbnail(); ?></a>
						<?php the_content(); ?>	
					</div>
				</div>
					<?php
					   $postID = get_the_ID();
					   $comment_array = get_approved_comments($postID);
					   $blogcount = count($comment_array);
					?>
				<div class="panel animated fadeIn panel-sq">
					<div class="panel-body">
							<h4 class="mg-md">
								<span class="ion ion-android-arrow-dropup"><?php echo $blogcount;?> 件のコメント</span>
							</h4>
						<?php $comments = get_comments(array(
									'post_id' => get_the_ID(),
									'status' => 'approve' 
								));   ?>		
						<?php foreach ($comments as $comment): ?>
						<div class="divider-h">
							<span class="divider"></span>
						</div>
							<div class="row">
								<div class="col-sm-12">
									<div class="row drag-obj">
										<div class="col-sm-8">
											<p>
												<?php echo $comment->comment_author; ?> Said:<br>
												<?php echo $comment->comment_content; ?>
											</p>
										</div>
										<div class="col-sm-4">
											<?php  echo get_avatar( $comment, $args['avatar_size'] ); ?>
										</div>
									</div>
								</div>
							</div>
							<?php endforeach; ?>
					</div>
				</div>
				<div class="panel animated fadeIn panel-sq">
					<div class="panel-body">
						<?php				
						$comment_args = array( 'title_reply'=>'コメントする',
						'fields' => apply_filters( 'comment_form_default_fields', array(
						'author' => '<p class="comment-form-author">' . '<label for="author">' . __( '名前 ' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
								'<input id="author" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required form-control" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',   
							'email'  => '<p class="comment-form-email">' .
										'<label for="email">' . __( 'メールアドレス(非公開) ' ) . '</label> ' .

										( $req ? '<span>*</span>' : '' ) .

										'<input id="email" name="email" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required form-control" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</p>',
							'url'    => '' ) ),
							'comment_field' => '<p>' .
										'<label for="comment">' . __( 'コメント' ) . '</label>' .
										'<textarea id="comment" name="comment"class="wpcf7-form-control wpcf7-textarea form-control" id="comment"  aria-required="true"></textarea>' .
										'<input id="redirectedlink" name="redirectedlink"  type="hidden" value="' . esc_attr(  $redirectedlink ) . '"  /></p>',
							'comment_notes_after' => '',
						);
						comment_form($comment_args); 
						?>
					</div>
				</div>
				<?php endwhile; ?>
				<div class="navigation">
					<span class="newer"><?php previous_posts_link(__('« Newer','example')) ?></span> <span class="older"><?php next_posts_link(__('Older »','example')) ?></span>
				</div><!-- /.navigation -->
				<?php else: ?>
				<div id="post-404" class="noposts">
					<p><?php _e('None found.','example'); ?></p>
				</div><!-- /#post-404 -->
				<?php endif; wp_reset_query(); ?>
		</div>
		<div class="col-sm-4">
				<h5 class="mg-md animated fadeIn sm-shadow">
					<span class="ion ion-ios-book-outline"><strong> 最近の投稿</strong></span>
				</h5>
				<?php
					$args = array( 'numberposts' => '4','post_type' => 'post', 'post_status' => 'publish', );
					$recent_posts = wp_get_recent_posts( $args );
					foreach( $recent_posts as $recent ){
						echo '<h5 class="mg-md animated hover-underline fadeIn sm-shadow"><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </h5> ';
					}
				?>	
		</div>
	</div>
</div>
</div>
<!-- blog END -->
<?php //edit_post_link(__('Edit this entry.', 'uscestheme'), '<div class="container bloc-lg">', '</div>'); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>