tunasdayavetama.com

Tes

Tes post

<?php

// Fungsi untuk menampilkan query post di Elementor Tab Widget
function custom_elementor_tab_query() {
    // Tentukan post type atau taxonomy yang akan ditampilkan
    $args = array(
        'post_type'      => 'post', // Ganti dengan CPT kamu jika perlu
        'posts_per_page' => 5, // Jumlah post yang ingin ditampilkan
        'order'          => 'DESC',
    );

    $query = new WP_Query($args);
    
    // Jika ada post yang ditemukan
    if ($query->have_posts()) :
        echo '<ul class="custom-tab-content">';
        while ($query->have_posts()) : $query->the_post();
            echo '<li>';
            echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
            echo '</li>';
        endwhile;
        echo '</ul>';
    else :
        echo '<p>Belum ada konten untuk ditampilkan.</p>';
    endif;
    wp_reset_postdata();
}

// Fungsi untuk menampilkan query post di FAQ Widget Elementor
function custom_elementor_faq_query() {
    // Tentukan post type atau taxonomy yang ingin ditampilkan di FAQ
    $args = array(
        'post_type'      => 'faq', // Ganti dengan post type FAQ jika ada
        'posts_per_page' => 5,
        'order'          => 'ASC',
    );

    $query = new WP_Query($args);

    // Jika ada FAQ yang ditemukan
    if ($query->have_posts()) :
        echo '<div class="faq-content">';
        while ($query->have_posts()) : $query->the_post();
            echo '<div class="faq-item">';
            echo '<h4>' . get_the_title() . '</h4>';
            echo '<div>' . get_the_content() . '</div>';
            echo '</div>';
        endwhile;
        echo '</div>';
    else :
        echo '<p>FAQ tidak tersedia.</p>';
    endif;
    wp_reset_postdata();
}

// Shortcode untuk menampilkan query di halaman atau widget
function custom_faq_tab_shortcode($atts) {
    ob_start();
    
    if (isset($atts['type']) && $atts['type'] === 'faq') {
        custom_elementor_faq_query(); // Menampilkan query untuk FAQ
    } else {
        custom_elementor_tab_query(); // Menampilkan query untuk Tab
    }
    
    return ob_get_clean();
}
add_shortcode('custom_faq_tab', 'custom_faq_tab_shortcode');

Leave a Reply

Your email address will not be published. Required fields are marked *