<?php
get_header(); ?> 	
 <div class="blogmain 	<?php if((get_option('fblogone') == true )): ?>hazfsidebar-sa<?php endif; ?>
">
 <div class="size">
 <div class="main-blog-1">
  	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

  <div class="main-blog-2">
 <h1><?php the_title(); ?></h1>
 <div class="blog-meta">
 <div class="blog-meta-user">
<?php
// Get author ID
$author_id = get_the_author_meta('ID');

// Get attachment ID
$avatar_attachment_id = get_user_meta($author_id, 'avatar', true);

// Get default avatar URL
$default_avatar_url = get_template_directory_uri() . '/img/user.jpg';

// Display author avatar
if ($avatar_attachment_id) {
  // Get image URL
  $avatar_url = wp_get_attachment_url($avatar_attachment_id);
  if ($avatar_url) {
    echo '<img src="' . esc_url($avatar_url) . '" alt="Author Avatar" width="100" height="100">';
  } else {
    // Display default avatar
    echo '<img src="' . esc_url($default_avatar_url) . '" alt="Default Avatar" width="100" height="100">';
  }
} else {
  // Display default avatar
  echo '<img src="' . esc_url($default_avatar_url) . '" alt="Default Avatar" width="100" height="100">';
}
?>
<h5><?php echo get_the_author_meta('display_name'); ?> </h5>
 
 </div>
 
 <div class="blog-meta-user">
 <span><i class="mdi mdi-timelapse"></i><?php the_time('d M Y'); ?></span>
 </div>
 
 <?php if((get_option('fblogtwo') == true )): ?>
  <div class="blog-meta-user dfgttyret">
 <span><i class="mdi mdi-timer"></i><?php $option_meta = rwmb_meta('shoghl'); if (!empty($option_meta)) { ?>
<?php echo $option_meta; ?>
<?php } ?> دقیقه زمان برای مطالعه</span>
 </div><?php endif; ?>
 </div>
 
 <div class="imgirani">
 
 <?php the_post_thumbnail(''); ?>
 </div>
 
 <div class="img-irani-p">
 <?php the_content(); ?>

 </div>
 
 
 <div class="share-123123">
 <div class="blog-rating">
<?php echo kk_star_ratings(); ?>
</div>
 <?php if((get_option('fblogthree') == true )): ?>
 <div class="share-iran-32">
 
 <a target="_blank" href="https://www.linkedin.com/shareArticle?mini=true&amp;url==<?php the_permalink(); ?>"><i class="mdi mdi-linkedin"></i></a>
 <a target="_blank" href="https://twitter.com/home?status=<?php the_permalink(); ?>"><i class="mdi mdi-twitter"></i></a>
 <a target="_blank" href="whatsapp://send?text=<?php the_permalink(); ?>"><i class="mdi mdi-whatsapp"></i></a>
<a target="_blank" href="http://www.facebook.com/sharer/sharer.php?m2w&s=100&p[url]=<?php the_permalink(); ?>"><i class="mdi mdi-facebook"></i></a>
<a target="_blank" href="https://telegram.me/share/url?url=<?php the_permalink(); ?>"><i class="mdi mdi-telegram"></i></a>

 </div><?php endif; ?>
 </div>
 <div class="post-n-meta meta-tag-1">
<?php the_tags( '', ' ', ''); ?>
</div>
<?php endwhile; endif; ?>

<div class="main-blog-1345435">
 <?php
		// Start the loop.
		while ( have_posts() ) : the_post();

			/*
			 * Include the post format-specific template for the content. If you want to
			 * use this in a child theme, then include a file called called content-___.php
			 * (where ___ is the post format) and that will be used instead.
			 */
			// If comments are open or we have at least one comment, load up the comment template.
			if ( comments_open() || get_comments_number() ) :
				comments_template();
			endif;

			// Previous/next post navigation.

		// End the loop.
		endwhile;
		?>
</div>
 </div>
 <?php if((get_option('fblogfour') == true )): ?>

<div class="main-blog-1 rr-blog-1">
<h2>مطالب مرتبط </h2>
<?php $related=get_posts(array('category__in'=>wp_get_post_categories($post->ID),
'orderby'=>'rand','numberposts'=>3,'post__not_in'=>array($post->ID)));
if($related) foreach($related as $post){ setup_postdata($post); ?>
<div class="product-list234234">
<div class="product-list-1234234">

<a class="rrf-eee" href="<?php the_permalink(); ?>">
	<?php the_post_thumbnail(''); ?>
<h3><?php the_title(); ?></h3>
</a>
<div class="list-dec">
<?php
$excerpt = get_the_excerpt();

$excerpt = substr($excerpt, 0, 160);
$result = substr($excerpt, 0, strrpos($excerpt, ' '));
echo $result;
?> </div>
<div class="list-meta">
<span class="list-meta-133334">
<?php
// Get author ID
$author_id = get_the_author_meta('ID');

// Get attachment ID
$avatar_attachment_id = get_user_meta($author_id, 'avatar', true);

// Get default avatar URL
$default_avatar_url = get_template_directory_uri() . '/img/user.jpg';

// Display author avatar
if ($avatar_attachment_id) {
  // Get image URL
  $avatar_url = wp_get_attachment_url($avatar_attachment_id);
  if ($avatar_url) {
    echo '<img src="' . esc_url($avatar_url) . '" alt="Author Avatar" width="100" height="100">';
  } else {
    // Display default avatar
    echo '<img src="' . esc_url($default_avatar_url) . '" alt="Default Avatar" width="100" height="100">';
  }
} else {
  // Display default avatar
  echo '<img src="' . esc_url($default_avatar_url) . '" alt="Default Avatar" width="100" height="100">';
}
?>
<h5><?php echo get_the_author_meta('display_name'); ?> </h5>

</span>
<span class="list-meta-2445435">
<?php the_time('d M Y'); ?>
</span>
</div>
</div></div>


<?php } wp_reset_postdata(); ?>
</div><?php endif; ?>
 </div>
 
 
 <div class="sidebar-blog">
 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('blog') ) : ?>
      <?php endif; ?>
 </div>
 </div>
 </div>
 
 

<?php get_footer();


