Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-03-26-experimental· MetaHugging Face LMArena Human Preference 140K

Dodaj do tych pól z ACF i do kodu counter - odliczanie dni i godzin. Kod powinien mieć…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with chatgpt-4o-latest-20250326’s answer.
  1. User

    Dodaj do tych pól z ACF i do kodu counter - odliczanie dni i godzin. Kod powinien mieć niezmienione class i style i prawidłowo działać. Oto kod pierwotny: function modal_shortcode(atts) { // Pobierz atrybuty shortcode atts = shortcode_atts(array( 'header' => 'Domyślny Nagłówek', 'text' => 'Domyślny tekst modala', 'background_image' => '', 'cta_text' => 'Dowiedz się więcej', 'cta_link' => '#' ), $atts, 'modal');

    // Pobierz pola ACF
    $header = get_field('modal_header', 14187) ?: $atts['header'];
    $text = wp_kses_post(get_field('modal_text', 14187) ?: $atts['text']);
    
    // Pobierz obraz tła (dostosuj nazwę pola i format zwracany przez ACF)
    $background_image = get_field('modal_background_image', 14187) ?: $atts['background_image'];
    // Jeśli pole ACF zwraca tablicę (Image Array), pobierz URL
    if (is_array($background_image)) {
        $background_image = $background_image['url'];
    }
    // Jeśli pole ACF zwraca ID (Image ID), pobierz URL
    elseif (is_numeric($background_image)) {
        $background_image = wp_get_attachment_image_url($background_image, 'full');
    }
    
    $cta_text = get_field('cta_text', 14187) ?: $atts['cta_text'];
    $cta_link = get_field('cta_link', 14187) ?: $atts['cta_link'];
    
    // Zbuduj HTML modala
    $modal_html = '
    
    return $modal_html;
    

    } add_shortcode('modal', 'modal_shortcode');

  2. Meta Assistant

    Oto zaktualizowany kod, który dodaje dwa nowe pola ACF: counter_end_date (data zakończenia odliczania) oraz counter_label (etykieta wyświetlana przed odliczaniem, np. "Czas pozostały:"). Następnie w kodzie HTML modala dodałem sekcję z odliczaniem dni i godzin do wskazanej daty zakończenia.

    function modal_shortcode($atts) {
        // Pobierz atrybuty shortcode
        $atts = shortcode_atts(array(
            'header' => 'Domyślny Nagłówek',
            'text' => 'Domyślny tekst modala',
            'background_image' => '',
            'cta_text' => 'Dowiedz się więcej',
            'cta_link' => '#',
            'counter_end_date' => '', // Nowy atrybut domyślny
            'counter_label' => 'Czas pozostały:' // Nowy atrybut domyślny
        ), $atts, 'modal');
    
        // Pobierz pola ACF z ID strony 14187 lub użyj atrybutów shortcode jako fallback
        $header = get_field('modal_header', 14187) ?: $atts['header'];
        $text = wp_kses_post(get_field('modal_text', 14187) ?: $atts['text']);
        
        // Pobierz obraz tła (dostosuj nazwę pola i format zwracany przez ACF)
        $background_image = get_field('modal_background_image', 14187) ?: $atts['background_image'];
        // Jeśli pole ACF zwraca tablicę (Image Array), pobierz URL
        if (is_array($background_image)) {
            $background_image = $background_image['url'];
        }
        // Jeśli pole ACF zwraca ID (Image ID), pobierz URL
        elseif (is_numeric($background_image)) {
            $background_image = wp_get_attachment_image_url($background_image, 'full');
        }
    
        $cta_text = get_field('cta_text', 14187) ?: $atts['cta_text'];
        $cta_link = get_field('cta_link', 14187) ?: $atts['cta_link'];
    
        // Nowe pola ACF dla countera
        $counter_end_date = get_field('counter_end_date', 14187) ?: $atts['counter_end_date'];
        $counter_label = get_field('counter_label', 14187) ?: $atts['counter_label'];
    
        // Konfiguracja countera
        $counter_html = '';
        if (!empty($counter_end_date)) {
            $end_time = strtotime($counter_end_date);
            if ($end_time > current_time('timestamp')) { // Wyświetlaj tylko jeśli data przyszła
                $counter_html = '
                <div class="modal-counter mt-4 mb-3 text-center">
                    <p class="fw-bold mb-2">' . esc_html($counter_label) . '</p>
                    <div class="d-flex justify-content-center gap-3" id="counter-timer" 
                         data-end-time="' . esc_attr(date('Y/m/d H:i:s', $end_time)) . '">
                        <div class="counter-box text-center">
                            <span class="counter-value fw-bold fs-3" id="counter-days">0</span>
                            <span class="counter-label d-block">dni</span>
                        </div>
                        <div class="counter-box text-center">
                            <span class="counter-value fw-bold fs-3" id="counter-hours">0</span>
                            <span class="counter-label d-block">godzin</span>
                        </div>
                    </div>
                </div>';
            }
        }
    
        // Zbuduj HTML modala
        $modal_html = '
    <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content position-relative">
                <!-- Dodanie diva z tłem jako overlay -->
                <div class="modal-background" style="background-image: url(' . esc_url($background_image) . ');"></div>
                <div class="modal-header">
                    <h2 class="card-title fw-bold" id="exampleModalLabel">' . esc_html($header) . '</h2>
                    <button type="button" class="btn btn-close material-symbols-outlined" 
            data-bs-dismiss="modal" aria-label="Close"
            style="color: rgba(200,115,40,1); font-size: 1.6rem; background: none; border: none;">
      close
    </button>
                </div>
                <div class="modal-body" style="min-height: 300px;">
                    ' . $text . '
                    ' . $counter_html . ' <!-- Wstawiamy counter -->
                </div>
                <div class="modal-footer">
                    <a href="' . esc_url($cta_link) . '" class="btn btn-secondary text-decoration-none px-3">' . esc_html($cta_text) . '</a>
                </div>
            </div>
        </div>
    </div>';
    
        // Dodajemy skrypt JS bezpośrednio w shortcode (można też załadować z osobnego pliku)
        $modal_html .= "
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                const counterElement = document.getElementById('counter-timer');
                if (counterElement) {
                    const endTime = new Date(counterElement.dataset.endTime).getTime();
    
                    function updateCounter() {
                        const now = new Date().getTime();
                        const timeLeft = endTime - now;
    
                        if (timeLeft <= 0) {
                            counterElement.innerHTML = '<p class=\"fw-bold text-danger\">Czas minął!</p>';
                            return;
                        }
    
                        const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
                        const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    
                        document.getElementById('counter-days').textContent = days;
                        document.getElementById('counter-hours').textContent = hours;
                    }
    
                    updateCounter(); // Uruchom raz przy ładowaniu
                    setInterval(updateCounter, 1000 * 60 * 60); // Odświeżaj co godzinę (możesz zmienić na 1000 dla sekund)
                }
            });
        </script>";
    
        return $modal_html;
    }
    add_shortcode('modal', 'modal_shortcode');
    

    Co nowego?

    1. Dodatkowe pola ACF:

      • counter_end_date (Data zakończenia, format: YYYY-MM-DD HH:MM:SS)
      • counter_label (Etykieta, np. "Czas pozostały:") Dodaj te pola w panelu administracyjnym ACF dla strony o ID 14187.
    2. HTML countera:

      • Dodano sekcję <div class="modal-counter"> wewnątrz .modal-body.
      • Zawiera dwa pola: dni i godziny.
    3. Skrypt JavaScript:

      • Osadzony w shortcode (możesz przenieść do osobnego pliku JS).
      • Pobiera datę zakończenia z atrybutu data-end-time.
      • Odlicza dni i godziny w czasie rzeczywistym.
      • Jeśli czas minie, wyświetla komunikat "Czas minął!".

    Jak skonfigurować ACF?

    1. W panelu WordPress przejdź do Custom Fields (ACF).
    2. Edytuj grupę pól przypisaną do strony 14187.
    3. Dodaj dwa nowe pola:
      • counter_end_date:
        • Typ pola: Date Time Picker.
        • Zapisz w formacie Y-m-d H:i:s (np. 2025-12-31 23:59:00).
      • counter_label:
        • Typ pola: Text.
        • Domyślnie: "Czas pozostały:".

    Jak używać shortcode?

    1. W panelu administracyjnym:

      [modal]
      

      Dane pobiorą się z ACF strony 14187.

    2. Z nadpisaniem:

      [modal counter_end_date="2025-01-01 00:00:00" counter_label="Promocja kończy się za:"]
      

      Nadpisujesz wtedy wartości z ACF.

    3. Stylowanie: Dodaj CSS do stylowania licznika, np.:

      .modal-counter {
          background: rgba(0, 0, 0, 0.1);
          padding: 15px;
          border-radius: 8px;
      }
      .counter-box {
          min-width: 80px;
      }
      .counter-value {
          color: #c87328;
      }
      

    Teraz wszystko powinno działać bez zmiany istniejących styli i struktury HTML. Jeśli data zakończenia jest ustawiona w ACF lub shortcode, pojawi się odliczanie. W przeciwnym razie sekcja zniknie.

    Testuj daty:

    • Przeszła data → wyświetla "Czas minął!".
    • Przyszła data → liczy dni i godziny.
    • Brak daty → sekcja nie jest renderowana.

    Miłego używania!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.