<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
global $post;

$view_counter = isset($campoal_options['conikal_view_counter_field']) ? $campoal_options['conikal_view_counter_field'] : 0;
$related_style = isset($campoal_options['conikal_related_style_field']) ? $campoal_options['conikal_related_style_field'] : 'list';
$single_post_style = isset($campoal_options['conikal_single_post_style_field']) ? $campoal_options['conikal_single_post_style_field'] : 'classic';
$related_post_per_page = isset($campoal_options['conikal_related_posts_per_page_field']) ? $campoal_options['conikal_related_posts_per_page_field'] : 3;
$categories = get_the_category($post->ID);
$author_id = get_post_field ('post_author', $post->ID);

if ($categories) :
    $args = array(
        'category__in' => array($categories[0]->term_id),
        'post__not_in' => array($post->ID),
        'posts_per_page' => $related_post_per_page,
        'ignore_sticky_posts' => false
    );

    $related_query = new WP_Query($args);

    if($related_query->have_posts()) : ?>
        <div class="ui divided items related-post-sticky">
        <?php while( $related_query->have_posts() ) : $related_query->the_post(); ?>
            <div class="item">
                <div class="content">
                    <a class="type bold" href="<?php the_permalink() ?>" data-bjax><?php the_title() ?></a>
                    <div class="meta"><?php the_author() ?></div>
                </div>
            </div>
        <?php endwhile; ?>
    </div>
    <div class="ui divider"></div>
    <?php 
    wp_reset_query();
    wp_reset_postdata();
endif; ?>
<?php endif; ?>
