Advertisement
pusatdata

WP Plugin: Advanced Custom Field

May 8th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. http://www.centerklik.com/cms/wordpress/tutorial-menggunakan-plugins-advanced-custom-field-wordpress/
  2.  
  3.  
  4.  
  5. ==================
  6. MASTER KALAU KOSONG TIDAK MUNCUL
  7. <!-- Let's show our custom fields here -->
  8. <?php
  9. $my_preview = get_post_meta( get_the_ID(), 'preview', true);
  10. $my_isbn = get_post_meta( get_the_ID(), 'isbn', true);
  11. if( ! empty( $my_preview ) ) {
  12. echo '<h3>Download: <a href="' . $my_preview . '" target="_blank">Link</a><h3>';
  13. }
  14. if( ! empty( $my_isbn ) ) {
  15. echo '<p>ISBN: ' . $my_isbn . '</p>';
  16. }
  17. ?>
  18. <!-- End showing our custom fields here -->
  19. ======================
  20.  
  21. LANGKAH MEMBUATNYA :
  22.  
  23. 1. Download Plugins Advanced Custom Field : http://wordpress.org/plugins/advanced-custom-fields/
  24. 2. Install dan aktifkan
  25. 3. Buat Kategori Theme Terlebih dahulu di postingan anda
  26. 4. Klik menu Custom Fields Di sidebar Halaman admin anda.
  27. 5. Klik Add New dan masukkan title dengan nama Theme
  28. 6. Klik button +Add Field dan tambahkan seperti aturan berikut
  29.  
  30. Author
  31.  
  32. Field Label = Author
  33. Field Name = author
  34. Field Type = text
  35.  
  36. Visit Site
  37.  
  38. Field Label = Visit Site
  39. Field Name = visit_site
  40. Field Type = text
  41.  
  42. Price
  43.  
  44. Field Label = Price
  45. Field Name = price
  46. Field Type = text
  47.  
  48. Responsive
  49.  
  50. Field Label = Responsive
  51. Field Name = Checkbox
  52. Field Type = text
  53. Choice = Yes : Yes
  54. No : No
  55.  
  56. Status
  57.  
  58. Field Label = Author
  59. Field Name = Checkbox
  60. Field Type = text
  61. Choice = Yes : Yes
  62. No : No
  63.  
  64. Jika anda sudah membuat setiap field dengan struktur seperti diatas maka nanti akan terlihat seperti gambar dibawah ini.
  65. advanced custom field wordpress tutorialSekarang atur Location Rules => Post Category – is equal to – Theme. Pengaturan Rule ini dimakasudkan hanya saat kita mencentang kategori Theme di post area barulah muncul field yang sudah kita buat tadi.
  66.  
  67. Atur Position di Option Normal (After content)
  68.  
  69. Jikas semuanya sudah selesai silahkan Buat postingan baru dan centang kategori theme di bawah button publish, lihat di bawah area postingan maka akan muncul field yang sudah anda buat.
  70.  
  71. Dan selanjutnya anda buka file single.php di theme wordpress anda dan masukkan code dibawah ini setelah code <?php the_content(); ?>
  72.  
  73. <?php the_field('author'); ?>
  74. <?php the_field('price'); ?>
  75. <?php the_field('responsive'); ?>
  76. <?php the_field('status'); ?>
  77. <?php the_field('visit_site'); ?>
  78.  
  79. ==============================================================================
  80. http://torquemag.io/2016/04/use-advanced-custom-fields-depth-tutorial/
  81.  
  82. My own setup ends up looking like this:
  83.  
  84. Field Label: Release Year
  85. Field Name: release_year
  86. Field Type: Number
  87. Field Instructions: Input the year of the book’s release here.
  88. Required: Yes
  89. I make this field required because I definitely want authors to fill this in (and myself as well).
  90.  
  91. Field Label: Author
  92. Field Name: author
  93. Field Type: Text
  94. Field Instructions: Please use the first and last name without any commas, e.g. “Stephen King, J.K. Rowling”.
  95. Required: Yes
  96. Formatting: No Formatting
  97. As you can see, I give clear instructions on how to use this field. The “no formatting” setting is to keep anyone from adding HTML here that would mess with my layout.
  98.  
  99. Field Label: Book Rating
  100. Field Name: book_rating
  101. Field Type: Number
  102. Field Instructions: Rate the quality of the book on a scale of one to ten.
  103. Required: Yes
  104. Minimum Value: 1
  105. Maximum Value: 10
  106. Step Size: 1
  107.  
  108. Kode di single.php atau single-postname.php denga nama single-book.php
  109.  
  110. <div class="book-meta">
  111. <ul>
  112. <li><strong>Author:</strong> <?php the_field('author'); ?></li>
  113. <li><strong>Release Year:</strong> <?php the_field('release_year'); ?></li>
  114. <li><strong>Book Rating:</strong> <?php the_field('book_rating'); ?>/10</li>
  115. </ul>
  116. </div>
  117.  
  118. ==============================================
  119. This is how I set up my fields:
  120.  
  121. Field Label: Movie Year
  122. Field Name: movie_year
  123. Field Type: Number
  124. Required: Yes
  125. Minimum Value: 1900
  126. Maximum Value: 2050
  127. Note the minimum and maximum values here—I set these to add some very basic validation, as it's unlikely we will have a movie older than 1900 and one newer than 2050 in the lifetime of the website.
  128.  
  129. Field Label: Movie Director
  130. Field Name: movie_director
  131. Field Type: Text
  132. Required: Yes
  133. Formatting: No formatting
  134. Since we are going to be formatting our output in our HTML, we don't want editors to be able to add HTML here that may interfere with our layout. Therefore, "no formatting" was chosen here.
  135.  
  136. Field Label: Movie Score
  137. Field Name: movie_score
  138. Field Type: Number
  139. Required: Yes
  140. Minimum Value: 1
  141. Maximum Value: 10
  142. Step Size: 1
  143. Again, we have a minimum and a maximum value set here to add some validation; our scores are out of ten, so we don't want editors to be able to insert a higher score than this. Likewise, we don't want any scores inserted that are lower than one.
  144.  
  145. Field Label: Movie IMDb Link
  146. Field Name: movie_imdb_link
  147. Field Type: Text
  148. Field Instructions: Paste the full IMDb URL in here. e.g. http://www.imdb.com/title/tt2015381/
  149. Required: Yes
  150. Formatting: No formatting
  151.  
  152. Kode di single.php atau single-postname.php denga nama single-movie.php
  153. <div class="reviews-meta">
  154. <ul>
  155. <li><?php _e('Year of release', 'movie'); ?>: <?php the_field('movie_year'); ?></li>
  156. <li><?php _e('Director', 'movie'); ?>: <?php the_field('movie_director'); ?></li>
  157. <li><?php _e('Rating', 'movie'); ?>: <?php the_field('movie_score'); ?>/10</li>
  158. <li><a href="<?php the_field('movie_imdb'); ?>" target="_blank"><?php _e('View on IMDb', 'movie'); ?></a></li>
  159. </ul>
  160. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement