Menambahkan PageLimit sebagai Param Dinamis di Form Filter Plugin Pods di WordPress
Hari ini saya mulai menggunakan plugin Pods CMS di situs blog ini. Setelah mengunjungi Situs Resmi Pod CMS, saya mengambil kesimpulan bahwa plugin ini memang yang terbaik saat ini apabila Anda ingin menambahkan halaman yang dapat dikostumais dan berisi data tertentu yang diambil dari database tanpa harus menggunakan fitur Post atau Page di situs WordPress Anda. Saya sudah mencoba dan mengutak-atik plugin ini, dan saya tertarik untuk ikut mengkostumais plugin ini, dengan menambahkan sedikit modifikasi supaya pengunjung dapat mengganti jumlah maksimum record per halaman pada form Filter.
- Buka file \pods\core\list_filters.php Anda, lalu cari kode ini:
44 45 46 47 48 49
// Display the search box and submit button $search = empty($_GET['search']) ? '' : $_GET['search']; ?> <input type="text" class="pod_search" name="search" value="<?php echo $search; ?>" /> <input type="submit" class="pod_submit" value="<?php echo $label; ?>" /> </form>ganti dengan kode di bawah ini:
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// Display the search box and submit button $search = empty($_GET['search']) ? '' : $_GET['search']; $pagelimit = empty($_GET['limit']) ? '10' : $_GET['limit']; ?> <input type="text" class="pod_search" name="search" value="<?php echo $search; ?>" /> Limit: <select name='limit'> <?php for ($x = 5; $x <= 50; $x += 5) { ?> <option value="<?=$x?>" <?=($pagelimit==$x )?'selected':''?>><?=$x?></option> <?php } ?> </select> <input type="submit" class="pod_submit" value="<?php echo $label; ?>" /> </form> -
Selanjutnya, sesuaikan PodPages milik Anda. Mari kita lihat contoh berikut. Sebelum penambahan pagelimit sebagai parameter yang bersifat dinamis, isi dari PodPages Anda seperti di bawah ini:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php get_header(); $Record = new Pod('state'); echo "<h2>States List</h2>"; echo $Record->getFilters(); echo "<br />"; // Pagelimit masih sebagai param statis di fungsi findRecords() $Record->findRecords('name ASC', 10); $total_rows = $Record->getTotalRows(); echo "Total Record = <b>".$total_rows."</b><br />"; echo $Record->getPagination(); echo "<br />"; echo "<table border='1' width='100%' cellpadding='2'>"; echo "<tr><td align='right' width='10%'><b>Rec#</b></td><td><b>Name</b></td></tr>"; echo $Record->showTemplate('state_list'); echo "</table>"; get_footer(); ?>
Setelah dimodifikasi, sekarang pagelimit sudah sebagai parameter yang dinamis, sehingga pengunjung Anda bisa menggantinya dari form Filter. Silahkan bandingkan PodPage di bawah ini dengan yang sebelumnya:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php get_header(); $Record = new Pod('state'); echo "<h2>States List</h2>"; echo $Record->getFilters(); echo "<br />"; // Sekarang pagelimit sudah sebagai param dinamis di form $pagelimit = empty($_GET['limit']) ? '10' : $_GET['limit']; $Record->findRecords('name ASC', $pagelimit); $total_rows = $Record->getTotalRows(); echo "Total Record = <b>".$total_rows."</b><br />"; echo $Record->getPagination(); echo "<br />"; echo "<table border='1' width='100%' cellpadding='2'>"; echo "<tr><td align='right' width='10%'><b>Rec#</b></td><td><b>Name</b></td></tr>"; echo $Record->showTemplate('state_list'); echo "</table>"; get_footer(); ?>
Demo:
- http://www.openscriptsolution.com/data/states/
- http://www.openscriptsolution.com/data/countries/
Selamat mengkode!
Cetak Artikel Ini
Komentar Terakhir