<?php
/*
 * ### LOOP RICERCA ###
 *
 */
?>

<?php
    $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; ?>

<section id="introricerca">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="titolo-sezione">
                    <h1><?php echo __('Results for','italiawp3'); ?>: "<?php echo get_search_query(); ?>"
                        <?php if($wp_query->max_num_pages != 0) { ?>
                        <br><small><?php echo __('Page','italiawp3'); ?> <?php echo $paged; ?> <?php echo __('of','italiawp3'); ?> <?php echo $wp_query->max_num_pages; ?></small>
                        <?php } ?>
                    </h1>
                </div>
            </div>
        </div>
    </div>
</section>

<section id="articolo-dettaglio-testo">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="articolo-paragrafi">
                    <div class="row">
                        <?php
                        /*
                         * role="status" (live region discreta): il conteggio dei risultati
                         * viene annunciato dagli screen reader senza interrompere la
                         * lettura. Prima era testo muto, e chi non vede la pagina non
                         * sapeva quanti risultati avesse trovato (WCAG 4.1.3).
                         *
                         * La classe d-none sotto i 768px nascondeva il conteggio anche
                         * agli AT: su mobile resta disponibile come testo per screen
                         * reader, cosi' l'informazione non dipende dalla larghezza.
                         */
                        ?>
                        <div class="col-md-12 cerca-risultati d-md-block d-none" role="status">
                            <?php echo esc_html($wp_query->found_posts); ?> <?php echo __('results found','italiawp3'); ?>
                        </div>
                        <div class="col-12 sr-only d-md-none" role="status">
                            <?php echo esc_html($wp_query->found_posts); ?> <?php echo __('results found','italiawp3'); ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="linetop"></div>
                        

<?php

    if (have_posts()) :
    while (have_posts()) : the_post();
    
    $category = get_the_category();
    
    $datapost = get_the_date('j F Y', '', ''); ?>
                        
                        <div class="col-lg-4 col-md-12">
                            <div class="cerca-risultato-item">
                                <div class="argomenti">
                                <?php
                                if (!empty($category)) {
                                    foreach ($category as $cat) {
                                        echo '<a href="' . esc_url(get_category_link($cat->term_id)) . '" title="' . esc_html($cat->name) . '" class="categoria mr16">' . esc_html($cat->name) . '</a>';
                                    }
                                }
                                ?>
                                </div>
                                <h2>
                                    <a href="<?php the_permalink(); ?>" title="<?php echo __('Go to the page','italiawp3'); ?>: <?php the_title(); ?>">
                                        <?php the_title(); ?>
                                    </a>
                                </h2>
                                <small><p><?php echo $datapost; ?></p></small>
                                <p><?php echo get_the_excerpt(); ?></p>
                                <a aria-label="<?php echo __('Read more','italiawp3'); ?> - <?php echo __('Go to the page','italiawp3'); ?>: <?php the_title(); ?>"
                                   href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="tutte">
                                    <?php echo __('Read more','italiawp3'); ?>
                                    <svg class="icon" aria-hidden="true" focusable="false">
                                        <use xlink:href="<?php echo esc_url( get_template_directory_uri() ); ?>/static/img/ponmetroca.svg#ca-arrow_forward"></use>
                                    </svg>
                                </a>
                            </div>
                            <div class="linetop"></div>
                        </div>

<?php endwhile;
      else : get_template_part('template-parts/error');
      endif; ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<?php get_template_part('template-parts/pagination');
