Edit File: pmihsan.php
<?php if( class_exists( 'CSF' ) ) { CSF::createWidget( 'orun_widget_post_module_ihsan', array( 'title' => esc_html__( 'Oruno - Yazı Modülü (Daha fazla göster)', 'orun' ), 'class' => 'orun-widget-fields', 'classname' => 'orun-widget-post-module-5', 'description' => esc_html__( 'Yazı listesini görüntüler.', 'orun' ), 'fields' => array( array( 'id' => 'title', 'type' => 'text', 'title' => esc_html__( 'Başlık:', 'orun' ), 'subtitle' => esc_html__( 'Yazı modülünün başlığını girin.', 'orun' ), 'help' => esc_html__( 'Yazı modülünün başlığını girin. Boş bırakırsanız modülün başlığı görünmez.', 'orun' ), ), array( 'id' => 'postcount', 'type' => 'number', 'title' => esc_html__( 'Yazı Sayısı:', 'orun' ), 'subtitle' => esc_html__( 'Yazı modülünde görüntülenecek yazı sayısını girin.', 'orun' ), 'help' => esc_html__( 'Varsayılan: 5, modülde kaç tane yazı görüntüleneceği belirleyin.', 'orun' ), 'default' => 6, ), array( 'id' => 'order', 'type' => 'select', 'title' => esc_html__( 'Sıralama:', 'orun' ), 'subtitle' => esc_html__( 'Yazıların sıralamasını seçin.', 'orun' ), 'help' => esc_html__( 'Yazılar seçtiğiniz sıralama türüne göre sıralanır.', 'orun' ), 'options' => array( 'date' => esc_html__( 'Son Eklenme Tarihine Göre', 'orun' ), 'modified' => esc_html__( 'Son Güncellenme Tarihine Göre', 'orun' ), 'meta_value_num' => esc_html__( 'En Çok Görüntülenme Sayısına Göre', 'orun' ), 'comment_count' => esc_html__( 'En Çok Yorum Sayısına Göre', 'orun' ), 'rand' => esc_html__( 'Rastgele', 'orun' ), ), ), array( 'id' => 'cat', 'type' => 'select', 'title' => esc_html__( 'Kategori:', 'orun' ), 'subtitle' => esc_html__( 'Yazıların görüntüleneceği kategori/kategorileri seçin.', 'orun' ), 'placeholder' => esc_html__( 'Tüm Kategoriler', 'orun' ), 'help' => esc_html__( 'Birden fazla kategori seçebilirsiniz. Hiç kategori seçmezseniz tüm kategorilerdeki yazılar listelenecektir.', 'orun' ), 'options' => 'categories', 'multiple' => true, 'chosen' => true, ), array( 'id' => 'offset', 'type' => 'number', 'title' => esc_html__( 'Offset Ayarı:', 'orun' ), 'subtitle' => esc_html__( 'Yazıların listelenmesi için offset ayarını girin.', 'orun' ), 'help' => esc_html__( 'Örnek: 5, yazıların 5. sıradan başlayarak listelenecektir.', 'orun' ), 'default' => '0', ), ) ) ); if( ! function_exists( 'orun_widget_post_module_ihsan' ) ) { function orun_widget_post_module_ihsan( $args, $instance ) { if ( ! empty( $instance['title'] ) ) { echo '<h2 style="display:none">'.$instance['title'].'</h2>'; } echo '<div class="orun-pm orun-pm-5 row">'; if (have_posts()): $args = array( 'order' => 'DESC', 'post_type' => 'post', 'posts_per_page' => $instance['postcount'], 'orderby' => $instance['order'], 'offset' => $instance['offset'], 'cat' => $instance['cat'], 'meta_key' => 'post_views_count', ); $query = new WP_Query( $args ); $i = 1; while($query->have_posts()): $query->the_post(); if ($i === 1): get_template_part('template-parts/post/post', '5'); elseif ($i === 2): get_template_part('template-parts/post/post', '5'); else: get_template_part('template-parts/post/post-5', '1'); endif; $i++; endwhile; endif; echo '<div class="" style="display: flex !important; justify-content: center !important;text-align:center">'; echo '<div class="load-more-container" style="background-color: #ccc; padding: 16px;">'; echo '<button class="load-more-button" style="background-color: #ccc; color: #fff; font-size: 16px;">Daha Fazla Göster</button>'; echo '</div>'; echo '</div>'; ?> <style> .row { display: flex !important; justify-content: center !important; } </style> <script> jQuery(document).ready(function($) { var page = 2; var canBeLoaded = true; var loadMoreContainer = $('.load-more-container'); $(document).on('click', '.load-more-button', function() { var button = $(this); var data = { 'action': 'load_more_posts', 'page': page, }; $.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', data: data, type: 'POST', beforeSend: function() { button.text('Yükleniyor...'); }, success: function(response) { if (response) { $('.orun-pm-5').append(response); page++; if (response.trim() == '') { canBeLoaded = false; } else { loadMoreContainer.css('display', 'none'); button.hide(); } } } }); }); }); </script> <?php echo '</div>'; echo '</div>'; } } } add_action('wp_ajax_load_more_posts', 'load_more_posts'); add_action('wp_ajax_nopriv_load_more_posts', 'load_more_posts'); function load_more_posts() { $instance = $_POST['instance']; // Orun widget örneği $args = array( 'order' => 'DESC', 'post_type' => 'post', 'posts_per_page' => $instance['postcount'], // Her seferinde widget ayarlarından alınan postcount değeri kadar yazı getir 'offset' => ($instance['postcount'] - 6) * ($_POST['page'] - 1), // Doğru offset değerini hesapla 'cat' => $instance['cat'], // Widget ayarlarından kategoriyi al 'orderby' => $instance['order'], // Widget ayarlarından sıralamayı al 'meta_key' => 'post_views_count', ); $query = new WP_Query($args); while ($query->have_posts()) { $query->the_post(); get_template_part('template-parts/post/post-5', '1'); } wp_die(); } ?>