<?php
/**
 * The default template for displaying content. Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 git
 */
?>

	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
		<div class="featured-post">
			<?php _e( 'Featured post', 'twentytwelve' ); ?>
		</div>
		<?php endif; ?>
		<header class="entry-header">
			<?php //the_post_thumbnail(); ?>
				
			<h1 class="entry-title">
			<?php if ( is_single() ) : ?>
				<?php the_title(); ?>
			<?php else : ?>
				<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
			<?php endif; // is_single() ?>
				<?php if ( comments_open() ) : ?>
				<span class="thecomment">
					<?php //comments_popup_link( '<span>' . __( '0', 'twentytwelve' ) . '</span>', __( '1', 'twentytwelve' ), __( '%', 'twentytwelve' ) ); ?>
					<?php comments_popup_link( '<span>' . '0' . '</span>', '1', '%' ); ?>
				</span>
				<?php endif; // comments_open() ?>
			</h1>
						
			<div class="entry-meta">
				<?php //twentytwelve_entry_meta(); ?>
				<?php date_auteur_meta(); 
				// POSTED IN FACEBOOK BY MYTHEMESHOP ON MAY 16, 2012 ?>
				<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '(<span class="edit-link">', '</span>)' ); ?>
			</div>
			
		</header><!-- .entry-header -->

		<?php $tags = wp_get_post_tags($post->ID); ?>

		<?php if ( is_search() ) : // Only display Excerpts for Search ?>
		<div class="entry-summary">
			<?php the_excerpt(); ?>
		</div><!-- .entry-summary -->
		<?php else : ?>
		<div class="entry-content">
			<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
			<?php //the_content(' '); ?>
			
			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
		</div><!-- .entry-content -->
		<?php endif; ?>

		<footer class="entry-meta">
			<?php //twentytwelve_entry_meta(); ?>
			<?php //edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>

			<?php if ( comments_open() ) : ?>
				<!--div class="comments-link">
					<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
				</div--><!-- .comments-link -->
			<?php endif; // comments_open() ?>

			<?php if (function_exists("st_related_posts") && !is_home()) {
					//st_related_posts('title=<h4 class="st-related-title">'.__( 'Related posts','unnamed').'</h4>&nopoststext='. __('','unnamed'). '&number=10&orderby=post_date&order=DESC');
					$arg = array(
					'xformat' => __('<a href="%post_permalink%" title="%post_title% (%post_date%)">%post_title%</a>', 'simpletags')
					);
					//st_related_posts($arg);
					}
			?>
			
			<!-- articles relatifs -->
			<?php 
			//if ( !is_home() && (get_option( 'similar' ) == ('1')) ) {
			if ( is_singular() && (get_option( 'similar' ) == ('1')) ) {
				$orig_post = $post;
				global $post;
				//$tags = wp_get_post_tags($post->ID);
	
				if ($tags) {
						$tag_ids = array();
						foreach ($tags as $individual_tag) {
							$tag_ids[] = $individual_tag->term_id;
							//print_r($individual_tag);
							}
							//echo $tag_ids[0] . " - "; // 22 GP - 1
							//echo $tag_ids[1]; // 30 moto - 5
						$args = array(
							'tag__in' => $tag_ids,
							'post__not_in' => array($post->ID),
							'posts_per_page' => 4,
							'caller_get_posts' => 1
							);
		
						$my_query= new wp_query($args);

						if( $my_query->have_posts() ) {
				?>
			<div class="relatedposts">
				<h3><?php _e('Related posts', 'twentytwelve-child');  ?>:</h3>				
				<?php						
					while ( $my_query->have_posts() ) {
						$my_query->the_post();
				?>	
						<div class="relatedthumb">
							<?php $vignette = first_image(get_the_ID()); 
							//echo $vignette;
							/*
							$attr = array(
								'src'	=> $vignette,
								'class'	=> "",
								'alt'	=> "",
								);
							the_post_thumbnail('similar-thumbnail', $attr);
							<!--img src="<?php //echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php //the_title(); ?>" /-->
							*/

							$vignette = get_bloginfo('stylesheet_directory') . "/timthumb.php?w=150&h=100&src=" . $vignette;
							?>				
							<a rel="external" href="<?php the_permalink() ?>">
								<img src="<?php echo $vignette; ?>" alt="<?php the_title(); ?>" />
								<?php the_title(); ?>
							</a>
						</div>
				<?php
						} // /while
					?>
			</div>
			<?php
			} // /if $my_query
		} // if ($tags)
		$post = $orig_post;
		wp_reset_query();

	} // !is_home()
	?>
	<!-- /articles relatifs -->
	
	
  		<p class="cls"></p>
			
			<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() && (get_option( 'description' ) == ('1')) ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
				<div class="author-info">
					<div class="author-avatar">
						<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 68 ) ); ?>
					</div><!-- .author-avatar -->
					<div class="author-description">
						<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
						<p><?php the_author_meta( 'description' ); ?></p>
						<div class="author-link">
							<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
								<?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentytwelve' ), get_the_author() ); ?>
							</a>
						</div><!-- .author-link	-->
					</div><!-- .author-description -->
				</div><!-- .author-info -->							
			<?php endif; ?>
			
			
			<?php if(!empty($tags) || !is_singular()) : ?>
				<div class="below-content tagged">
					<?php if(has_tag()) : ?>
						<div class="tags">
							<svg version="1.1" width="18px" height="18px" viewBox="0 0 48 48">
								<path d="M 41.29511 48 L 41.29511 .091884613 L 6.999998 .091884613 L 6.999998 47.78994 L 24.042513 30.74741 Z" />
							</svg>
							<div class="the_tags">
								<?php the_tags('') ?>
							</div>
						</div>
					<?php endif ?>
					<!--/div-->
				<?php endif ?>	

						<div class="update">
							<?php twentytwelve_post_updated(); ?>
						</div>
					<div class="clear"></div>
				</div> <!-- /below-content -->
			
		</footer><!-- .entry-meta -->
	</article><!-- #post -->
