<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Xarxaprod_theme
 */

?>
<!-- template-parts content-xarxaprod-convo-php -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<header class="entry-header">
		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
	</header><!-- .entry-header -->

	<section class="xarxaprod-convo-info-fields">
   <ul>
	  <?php if( get_field('xxp_convo_espai_associat') ):
   	// read here howto
   // https://www.advancedcustomfields.com/resources/relationship/#display-list-of-posts-with-setuppostdata
      $espai_associat_posts = get_field('xxp_convo_espai_associat');
      if( $espai_associat_posts ): 
        foreach( $espai_associat_posts as $post ):
        // Setup this post for WP functions (variable must be named $post).
        setup_postdata($post); ?>
  	    <li class="xarxaprod-convo-espai-associat">
  		  	<dt>Espai Associat</dt>
          <dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd>
  	    </li>
  	    <li class="xarxaprod-convo-associat-address">
  		  	<dt>Lloc</dt>
          <dd><a href="<?php the_permalink(); ?>"><?php the_field('xxp_associat_address'); ?></a></dd>
  	    </li>
         <?php endforeach; 
       // Reset the global post object so that the rest of the page works correctly.
       wp_reset_postdata(); 
			else: ?>

        <?php if( get_field('xxp_convoer_name') ): ?>
	      <li class="xarxaprod-convo-field">
  		  	<dt>Centre</dt>
          <dd class="xarxaprod-convoer-name"><?php the_field('xxp_convoer_name'); ?></dd>
		    </li>
		    <?php endif; ?>

			<?php endif; //end if has posts espai associat ?>

		<?php endif; //end if has relation with other espai associat ?>


	  <li class="xarxaprod-convo-field">
      <dt>Disciplines</dt>
		  <dd><?php get_template_part( 'template-parts/section', 'list-checkbox', array('iterate_field' => 'xxp_convo_field') ); ?></dd>
		</li>

	  <li class="xarxaprod-convo-info-date">
      <dt>Termini</dt>
     <?php if( get_field('xxp_convo_apply_begin') || get_field('xxp_convo_apply_end') ): ?>
			<dd class="xarxaprod-label item-xxp_convo_dates">
				<span class="item-xxp_convo_apply_begin">del <?php the_field('xxp_convo_apply_begin'); ?> </span>
        <span class="item-xxp_convo_apply_end">al <?php the_field('xxp_convo_apply_end'); ?> </span>
				<?php if( get_field('xxp_convo_apply_text') ): ?>
          <br />
          <span class="item-xxp_convo_apply_text"><?php the_field('xxp_convo_apply_text'); ?></span>
		    <?php endif; ?>
      </dd>
     <?php endif; ?>
    </li>

	  <li class="xarxaprod-convo-info-date">
      <dt>Periode</dt>
     <?php if( get_field('xxp_convo_date_begin') || get_field('xxp_convo_date_end') ): ?>
			<dd class="xarxaprod-label item-xxp_convo_dates">
        del
				<span class="item-xxp_convo_date_begin">del <?php the_field('xxp_convo_date_begin'); ?> </span>
        al
        <span class="item-xxp_convo_date_end">al <?php the_field('xxp_convo_date_end'); ?> </span>
      </dd>
     <?php endif; ?>
    </li>
	</ul>
  </section>

	<div class="entry-content">
		<?php
		the_content(
			sprintf(
				wp_kses(
					/* translators: %s: Name of current post. Only visible to screen readers */
					__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'xarxaprod' ),
					array(
						'span' => array(
							'class' => array(),
						),
					)
				),
				wp_kses_post( get_the_title() )
			)
		);
		wp_link_pages(
			array(
				'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'xarxaprod' ),
				'after'  => '</div>',
			)
		);
		?>
	</div><!-- .entry-content -->

	<footer class="entry-footer">
		<?php xarxaprod_entry_footer(); ?>
	</footer><!-- .entry-footer -->
</article><!-- #post-<?php the_ID(); ?> -->
