<?php
/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage Probit
 *
 */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php
    $class = 'col-sm-12';
    if (has_post_thumbnail()) {
        $class = 'col-sm-7';
    }
    if (!is_single() && !is_search()) {
        ?>
        <div class="blog_div">
            <?php if (has_post_thumbnail()) { ?>
                <div class="blog_img col-xs-12 col-sm-5">
                    <a href="<?php the_permalink(); ?>">
                        <?php
                        if (has_post_thumbnail()) {
                            the_post_thumbnail('probit-blogpage-img');
                        }
                        if (is_sticky() && is_home() && !is_paged()) :
                            ?>
                            <div class="featured-post">
                                <?php _e('Featured post', 'probit'); ?>
                            </div><?php
                        endif;
                        ?>
                    </a>
                </div><?php }
                    ?>
            <div class="blog_content col-xs-12 <?php echo $class; ?> padding_right_0">
                <div class="blog_title pull-left">
                    <h3 class="text-capitalize">
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </h3>
                    <div class="postmeta">
                        <?php
                        if ('team' != get_post_type()) {
                            ?>
                            <div class="postdate headerfont" itemprop="datePublished">
                                <span class="postday"><?php echo esc_html(get_the_date("d")); ?></span>
                                <?php echo esc_html(get_the_date("M Y")); ?>
                            </div>
                            <?php
                        }
                        ?>
                    </div>
                </div>
                <div class="col-xs-12 padding_left_0 text-justify">
                    <p><?php echo wp_trim_words(get_the_excerpt(), 50, ' &hellip;'); ?></p>
                </div>
            </div>
            <footer class="blog_footer text-capitalize">
                <?php
                if ('team' != get_post_type()) {
                    ?>
                    <span><i class="fa fa-user"></i><?php echo esc_attr(get_the_author()); ?></span>
                    <?php
                }
                if ('portfolio' == get_post_type()) {
                    $separtor = ' ';
                    // get lists of term associated in the current post type
                    $terms = get_the_terms(get_the_ID(), 'portfoliocategories');
                    if ($terms != "") {
                        ?>
                        <span><i class="fa fa-bookmark"></i>
                            <?php
                            foreach ($terms as $term) {
                                // get term link, the function name explain it
                                $term_link = get_term_link($term, 'portfoliocategories');

                                // the function explain its purpose
                                if (is_wp_error($term_link))
                                    continue;

                                // display term name with link
                                echo $separtor . '<a href="' . $term_link . '">' . $term->name . '</a>';
                                $separtor = ' , ';
                            }
                            ?>
                        </span>
                        <?php
                    }
                }

                if (comments_open()) :
                    comments_popup_link('<span class="leave-reply"><i class="fa fa-comment"></i>0</span>', '<span class="leave-reply"><i class="fa fa-comment"></i>1</span>', '<span class="leave-reply"><i class="fa fa-comment"></i>%</span>');
                endif; // comments_open()

                if ('post' == get_post_type()) {
                    // Translators: used between list items, there is a space after the comma.
                    $categories_list = get_the_category_list(', ');

                    // Translators: used between list items, there is a space after the comma.
                    $tag_list = get_the_tag_list('', ', ');

                    if ($categories_list != "") {
                        ?>
                        <span><i class="fa fa-bookmark"></i><?php echo $categories_list; ?></span>
                        <?php
                    }

                    if ($tag_list != "") {
                        ?>
                        <span class="probit-tags"><i class="fa fa-tag"></i><?php echo $tag_list; ?></span>
                        <?php
                    }
                }
                ?>
                <div class="read_more">
                    <a href="<?php the_permalink(); ?>" class="text-capitalize"><i class="fa fa-plus"></i><?php _e('Read More', 'probit'); ?></a>
                </div>
            </footer>
        </div>
        <?php
    } else if (is_search()) {
        ?>
        <div class="blog_div">
            <h2 class="col-xs-12">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </h2>
            <div class="col-xs-12">
                <?php the_excerpt(); ?>
            </div>
        </div>
        <?php
    }

    if (is_single()) :
        ?>
        <div class="single-post-thumbnail">
            <?php
            if (!post_password_required() && !is_attachment()) :
                the_post_thumbnail('probit_single_post_img');
            endif;
            ?>
        </div><!-- .entry-header -->
        <?php
    endif; // comments_open()

    if (is_single()) :
        ?>
        <div class="entry-content">
            <?php the_content(__('Continue reading', 'probit') . ' <span class="meta-nav">&rarr;</span>'); ?>
            <?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'probit'), 'after' => '</div>')); ?>
        </div><!-- .entry-content -->
        <?php
    endif;

    if (is_single()) :
        ?>
        <footer class="entry-meta">
            <div class="postmeta_div">
                <?php
                if ('post' == get_post_type()) {
                    probit_posted_on();

                    // Translators: used between list items, there is a space after the comma.
                    $categories_list = get_the_category_list(', ');

                    // Translators: used between list items, there is a space after the comma.
                    $tag_list = get_the_tag_list('', ', ');

                    if ($categories_list != "") {
                        ?>
                        <span><i class="fa fa-bookmark"></i><?php echo $categories_list; ?></span>
                        <?php
                    }

                    if ($tag_list != "") {
                        ?>
                        <span><i class="fa fa-tag"></i><?php echo $tag_list; ?></span>
                        <?php
                    }
                } elseif ('portfolio' == get_post_type()) {
                    $separtor = ' ';
                    // get lists of term associated in the current post type
                    $terms = get_the_terms(get_the_ID(), 'portfoliocategories');
                    if ($terms != "") {
                        ?>
                        <span><i class="fa fa-bookmark"></i>
                            <?php
                            foreach ($terms as $term) {
                                // get term link, the function name explain it
                                $term_link = get_term_link($term, 'portfoliocategories');

                                // the function explain its purpose
                                if (is_wp_error($term_link))
                                    continue;

                                // display term name with link
                                echo $separtor . '<a href="' . $term_link . '">' . $term->name . '</a>';
                                $separtor = ' , ';
                            }
                            ?>
                        </span>
                        <?php
                    }
                }elseif ('team' == get_post_type()) {
                    $separtor = ' ';
                    $terms = wp_get_post_terms(get_the_ID(), 'team-category');
                    if ($terms != "") {
                        ?>
                        <span class="our-team-designation">
                            <?php
                            foreach ($terms as $term) {
                                // get term link, the function name explain it
                                $term_link = get_term_link($term, 'team-category');

                                // the function explain its purpose
                                if (is_wp_error($term_link))
                                    continue;

                                // display term name with link
                                echo $separtor . '<a href="' . $term_link . '">' . $term->name . '</a>';
                                $separtor = ' ';
                            }
                            ?>
                        </span>
                        <?php
                    }
                }
                ?>
            </div>

            <?php
            if (is_singular() && get_the_author_meta('description') && is_multi_author()) :
                // 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
                        /** This filter is documented in author.php */
                        $author_bio_avatar_size = apply_filters('probit_author_bio_avatar_size', 68);
                        echo get_avatar(get_the_author_meta('user_email'), $author_bio_avatar_size);
                        ?>
                    </div><!-- .author-avatar -->
                    <div class="author-description">
                        <h2><?php printf(__('About', 'probit') . ' ' . esc_attr(get_the_author())); ?></h2>
                        <p><?php esc_attr(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', 'probit') . ' <span class="meta-nav">&rarr;</span> ' . get_the_author()); ?>
                            </a>
                        </div><!-- .author-link	-->
                    </div><!-- .author-description -->
                </div><!-- .author-info -->
                <?php
            endif;
            ?>
        </footer><!-- .entry-meta -->
    <?php endif; ?>
</article><!-- #post -->
