<div class="flickity-carousel carousel3 js-flickity"
     data-flickity='{ "prevNextButtons": false, "lazyLoad": true, "initialIndex": 0, "freeScroll": false, "autoPlay": 6500, "pageDots": false }'>

<?php
$can = 0;

// Traer hasta 6 notas de tapa
$sql = "SELECT ID, foto, ext_img, titulo, texto, nota
        FROM notas_tapa
        WHERE cu3er = '1'
        ORDER BY ID DESC
        LIMIT 6";

if ($result = $conn->query($sql)) {
    while ($row = $result->fetch_assoc()) {
        $ID_nota  = $row['ID'];
        $foto     = $row['foto'];
        $ext_img  = $row['ext_img'];
        $titulo   = $row['titulo'];
        $texto    = $row['texto'];
        $nota     = (int)$row['nota'];

        $can++;

        // Buscar título real de la nota (tabla notas) si aplica
        $titulo11 = '';
        $ext_img2 = '';

        if ($nota !== 0) {
            $stmt = $conn->prepare("SELECT titulo, ext_img FROM notas WHERE ID = ? LIMIT 1");
            if ($stmt) {
                $stmt->bind_param("i", $nota);
                $stmt->execute();
                $stmt->bind_result($titulo11, $ext_img2);
                $stmt->fetch();
                $stmt->close();
            }
        }

        // Limpiar <em> como hacías antes
        $texto_clean = str_replace(['<em>', '</em>'], '', (string)$texto);
        ?>
        
        <div class="carousel-cell3">

            <?php if ($nota !== 0) { ?>
                <a target="_parent"
                   href="<?php echo $dom; ?>/nota/<?php echo $nota; ?>/<?php echo urls_amigables($titulo11); ?>"
                   class="carouselimg">
            <?php } ?>

                    <img class="carousel-cell-image"
                         data-flickity-lazyload="<?php echo $dom; ?>/upload_pic/thumbnail_<?php echo htmlspecialchars($foto, ENT_QUOTES, 'UTF-8'); ?>.jpg"
                         alt="<?php echo htmlspecialchars($titulo, ENT_QUOTES, 'UTF-8'); ?>">

                    <div class="news-summary">
                        <h3 class="colorTitulo"><?php echo htmlspecialchars($titulo, ENT_QUOTES, 'UTF-8'); ?></h3>
                        <div class="mom-post-meta nb-item-meta">
                            <span class="entry-date"><?php echo $d; ?> de <?php echo $m; ?>, <?php echo $a; ?></span>
                        </div>
                        <span class="bajada">
                            <p class="selectionShareable" style="margin-bottom:0;">
                                <?php echo $texto_clean; ?>
                            </p>
                        </span>
                    </div>

            <?php if ($nota !== 0) { ?>
                </a>
            <?php } ?>

        </div>

        <?php
    }
    $result->free();
}
?>

</div>