<?php
/**
 * Template part for displaying each convo with each field in category, archive, search  
 * to be used inside the loop.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Xarxaprod_theme
 * @used_by page-template/convo-serach.php
 * @used_by page-template/convo-archive.php
 *
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class('xarxaprod-card-each'); ?> >
   <h3 class="entry-title">
     <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark">
       <?php the_title(); ?>
     </a>
   </h3>


  <section class="xarxaprod-convo-info-fields">
   <ul>
    <li class="xarxaprod-convo-info-date">
     <?php if( get_field('xxp_convo_apply_begin') || get_field('xxp_convo_apply_end') ): ?>
      <dt>Termini</dt>
      <dd class="xarxaprod-label item-xxp_convo_dates">
        <?php if( get_field('xxp_convo_apply_begin') ): ?>
        <span class="item-xxp_convo_apply_begin">del <?php the_field('xxp_convo_apply_begin'); ?> </span>
        <?php endif; ?>
        <?php  if( get_field('xxp_convo_apply_end') && !get_field('xxp_convo_apply_begin') ){ echo 'fins'; } ?>
     <?php if( get_field('xxp_convo_apply_end') ): ?>
        <span class="item-xxp_convo_apply_end">al <?php the_field('xxp_convo_apply_end'); ?> </span>
        <?php endif; ?>
        <?php if( get_field('xxp_convo_apply_text') ): ?>
          <span class="item-xxp_convo_apply_text"><?php the_field('xxp_convo_apply_text'); ?></span>
        <?php endif; ?>
      </dd>
     <?php endif; ?>
    </li>
   <?php if( ! get_field('xxp_convo_espai_associat') ): ?>
     <?php // read here howto ?>
     <?php // https://www.advancedcustomfields.com/resources/relationship/#display-list-of-posts-with-setuppostdata ?>
        <?php if( get_field('xxp_convoer_name') ): ?>
        <li class="xarxaprod-convo-field">
          <dt></dt>
          <dd class="xarxaprod-convoer-name"><?php the_field('xxp_convoer_name'); ?></dd>
        </li>
        <?php endif; ?>
     <?php else: //exists get_field('xxp_convo_espai_associat')?>
       <?php $espai_associat_posts = get_field('xxp_convo_espai_associat'); ?>
       <?php foreach( $espai_associat_posts as $thispost ): ?>
       <?php  // Setup this post for WP functions (variable must be named $post).?>
            <li class="xarxaprod-convo-espai-associat">
              <dt></dt>
              <dd><a href="<?php echo ($thispost->guid);//the_permalink(); ?>"><?php echo ($thispost->post_title); ?><?php //the_title(); ?></a></dd>
            </li>
       <?php endforeach; ?>
       <?php // Reset the global post object so that the rest of the page works correctly.?>
   <?php endif; //end get_field('xxp_convo_espai_associat') ?>
  </ul>
</section>



         <section class="excerpt post-excerpt">
             <?php //the_excerpt() ?>
            <?php echo wp_trim_words(get_the_excerpt(), 30); // https://developer.wordpress.org/reference/functions/wp_trim_words/?>

         </section>

         <aside>
<?php get_template_part( 
  'template-parts/section', 
  'list-checkbox', 
  array('iterate_field' => 'xxp_convo_field') 
); ?>

<?php get_template_part( 
  'template-parts/section', 
  'list-checkbox', 
  array('iterate_field' => 'xxp_convo_territory') 
); ?>

<?php get_template_part( 
  'template-parts/section', 
  'list-checkbox', 
  array('iterate_field' => 'xxp_convo_service') 
); ?>

         </aside>

         <nav class="more-link">
         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark" class="button button-more">
            Més info
            <span class="hide"><?php the_title(); ?></span>
           </a>
         </nav>

       </article><!-- #post-<?php the_ID(); ?> -->