Advertisement
pusatdata

WP-Trik Menampilkan Post Terbaru dari Kategori Tertentu

Jan 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. http://www.wpbeginner.com/wp-tutorials/how-to-display-recent-posts-from-a-specific-category-in-wordpress/
  2.  
  3. ======================
  4. MASTER SCRIPT KODE:
  5. ======================
  6. <?php
  7. $catquery = new WP_Query( 'cat=3&posts_per_page=10' );
  8. while($catquery->have_posts()) : $catquery->the_post();
  9. ?>
  10. BENTUK LOOP POST disini
  11. <?php endwhile; ?>
  12.  
  13. KETERANGAN:
  14. 1. Angka 3 adalah ID Category
  15. 2. Angka 10 adalah banyaknya tampilan post
  16.  
  17.  
  18. CONTOH PEMAKAIAN:
  19. 1. Seperti Home Buku
  20. <?php
  21. $catquery = new WP_Query( 'cat=1&posts_per_page=10' );
  22. while($catquery->have_posts()) : $catquery->the_post();
  23. ?>
  24.  
  25. <div class="post-box">
  26. <div class="view view-seventh">
  27. <img src="/img/cover/<?php the_title(); ?>.jpg" style="width:164px;" onError="this.src='/nocover.jpg';">
  28. <div class="mask">
  29. <h2>
  30. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  31. <?php the_title(); ?></a>
  32. </h2>
  33.  
  34. <p><span class="meta_tags">by <?php the_tags('', ', ', ''); ?></span> <span class="meta_date"><?php echo get_the_date(); ?></span> <span class="meta_categories"><?php the_category(', '); ?></span> <span class="meta_edit"><?php edit_post_link(); ?></span></p>
  35. <a href="<?php the_permalink(); ?>" class="info">Read More</a>
  36.  
  37. </div>
  38. </div>
  39. </div>
  40.  
  41.  
  42.  
  43. <?php endwhile; ?>
  44.  
  45.  
  46. 2. Asli Bawaan Contoh Sumber
  47. <?php
  48. $catquery = new WP_Query( 'cat=3&posts_per_page=10' );
  49. while($catquery->have_posts()) : $catquery->the_post();
  50. ?>
  51. <ul>
  52. <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
  53.  
  54. <ul><li><?php the_content(); ?></li>
  55. </ul>
  56. </li>
  57. </ul>
  58. <?php endwhile; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement