<?php
/**
 * The default template for displaying content
 *
 * Used for both singular and index.
 *
 * @package WordPress
 * @subpackage TheHoot
 */

?>
  <?php
$title = get_the_title();
$permalink = get_the_permalink();
$featured_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
$author_id = get_the_author_meta( 'ID' );
$author = get_the_author_meta( 'display_name', $author_id );
$date = get_the_date();
$content = apply_filters( 'the_content', get_the_content() );
$excerpt = get_the_excerpt();
$currentID = get_the_ID();
// Get primary (Yoast) term if it is set
$category_display = '';
$category_slug = '';
$category = get_the_category();

if ( class_exists('WPSEO_Primary_Term') ) {
     // Show the post's 'Primary' category, if this Yoast feature is available, & one is set
	$wpseo_primary_term = new WPSEO_Primary_Term( 'category', get_the_id() );
	$wpseo_primary_term = $wpseo_primary_term->get_primary_term();
	$term = get_term( $wpseo_primary_term );

     if ( is_wp_error( $term ) ) {
          // Default to first category (not Yoast) if an error is returned
          $category_display = $category[0]->name;
          $category_slug = $category[0]->slug;
     } else {
          // Set variables for category_display & category_slug based on Primary Yoast Term
          $category_id = $term->term_id;
          $category_term = get_category($category_id);
          $category_display = $term->name;
          $category_slug = $term->slug;
     }
} else {
     // Default, display the first category in WP's list of assigned categories
     $category_display = $category[0]->name;
     $category_slug = $category[0]->slug;
}
?>

    <?php if ( is_singular() ) : ?>

      <article>

        <?php if ($category_display): ?>

          <p class="category">
            <?php echo $category_display; ?>
          </p>

          <?php endif; ?>

            <h1><?php echo esc_html($title); ?></h1>

            <?php if ($excerpt) : ?>

              <p class="excerpt">
                <?php echo ($excerpt); ?>
              </p>

              <?php endif; ?>

                <div class="meta">
                  <a class="mb-4" href="<?php echo esc_url( get_author_posts_url( $author_id ) ); ?>" title="<?php echo ($author); ?>">

  <img src="<?php echo get_avatar_url($author_id); ?>" width="40" height="40" class="avatar rounded-circle" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />

<?php echo ($author); ?>
</a> -
                  <?php echo $date; ?>
                </div>

                <?php if ($featured_image) : ?>

                  <img class="img-fluid w-100 featured mb-4" src="<?php echo $featured_image[0]; ?>" />

                  <?php endif; ?>

                  <?php echo html_entity_decode(get_the_content()); ?>

      </article>

      <?php else : ?>

        <div class="col-12 col-md-6 col-lg-4">
          <a href="<?php echo $permalink; ?>" class="relative block w-full">
            <div class="card h-100 mt-3">

              <?php if ($featured_image) : ?>

                <img class="img-fluid w-100 featured mb-4" src="<?php echo $featured_image[0]; ?>" />

                <?php endif; ?>

                  <div class="card-body d-flex flex-column p-4">
                    <div class="date mb-3">

                      <?php the_time(get_option('date_format')); ?>

                    </div>
                    <h3 class="h4">

             		<?php echo $title; ?>

							</h3>
                    <p>
                      <?php echo limit_words(get_the_excerpt(), '14'),'...'; ?>
                    </p>
                    <div class="mt-auto mb-3">
                      <button class="mx-auto btn btn-sm mt-auto">Read more &#8594;</button>
                    </div>
                  </div>
            </div>
          </a>
        </div>

        <?php endif; ?>
