Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://www.centerklik.com/cms/wordpress/tutorial-menggunakan-plugins-advanced-custom-field-wordpress/
- ==================
- MASTER KALAU KOSONG TIDAK MUNCUL
- <!-- Let's show our custom fields here -->
- <?php
- $my_preview = get_post_meta( get_the_ID(), 'preview', true);
- $my_isbn = get_post_meta( get_the_ID(), 'isbn', true);
- if( ! empty( $my_preview ) ) {
- echo '<h3>Download: <a href="' . $my_preview . '" target="_blank">Link</a><h3>';
- }
- if( ! empty( $my_isbn ) ) {
- echo '<p>ISBN: ' . $my_isbn . '</p>';
- }
- ?>
- <!-- End showing our custom fields here -->
- ======================
- LANGKAH MEMBUATNYA :
- 1. Download Plugins Advanced Custom Field : http://wordpress.org/plugins/advanced-custom-fields/
- 2. Install dan aktifkan
- 3. Buat Kategori Theme Terlebih dahulu di postingan anda
- 4. Klik menu Custom Fields Di sidebar Halaman admin anda.
- 5. Klik Add New dan masukkan title dengan nama Theme
- 6. Klik button +Add Field dan tambahkan seperti aturan berikut
- Author
- Field Label = Author
- Field Name = author
- Field Type = text
- Visit Site
- Field Label = Visit Site
- Field Name = visit_site
- Field Type = text
- Price
- Field Label = Price
- Field Name = price
- Field Type = text
- Responsive
- Field Label = Responsive
- Field Name = Checkbox
- Field Type = text
- Choice = Yes : Yes
- No : No
- Status
- Field Label = Author
- Field Name = Checkbox
- Field Type = text
- Choice = Yes : Yes
- No : No
- Jika anda sudah membuat setiap field dengan struktur seperti diatas maka nanti akan terlihat seperti gambar dibawah ini.
- 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.
- Atur Position di Option Normal (After content)
- 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.
- Dan selanjutnya anda buka file single.php di theme wordpress anda dan masukkan code dibawah ini setelah code <?php the_content(); ?>
- <?php the_field('author'); ?>
- <?php the_field('price'); ?>
- <?php the_field('responsive'); ?>
- <?php the_field('status'); ?>
- <?php the_field('visit_site'); ?>
- ==============================================================================
- http://torquemag.io/2016/04/use-advanced-custom-fields-depth-tutorial/
- My own setup ends up looking like this:
- Field Label: Release Year
- Field Name: release_year
- Field Type: Number
- Field Instructions: Input the year of the book’s release here.
- Required: Yes
- I make this field required because I definitely want authors to fill this in (and myself as well).
- Field Label: Author
- Field Name: author
- Field Type: Text
- Field Instructions: Please use the first and last name without any commas, e.g. “Stephen King, J.K. Rowling”.
- Required: Yes
- Formatting: No Formatting
- 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.
- Field Label: Book Rating
- Field Name: book_rating
- Field Type: Number
- Field Instructions: Rate the quality of the book on a scale of one to ten.
- Required: Yes
- Minimum Value: 1
- Maximum Value: 10
- Step Size: 1
- Kode di single.php atau single-postname.php denga nama single-book.php
- <div class="book-meta">
- <ul>
- <li><strong>Author:</strong> <?php the_field('author'); ?></li>
- <li><strong>Release Year:</strong> <?php the_field('release_year'); ?></li>
- <li><strong>Book Rating:</strong> <?php the_field('book_rating'); ?>/10</li>
- </ul>
- </div>
- ==============================================
- This is how I set up my fields:
- Field Label: Movie Year
- Field Name: movie_year
- Field Type: Number
- Required: Yes
- Minimum Value: 1900
- Maximum Value: 2050
- 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.
- Field Label: Movie Director
- Field Name: movie_director
- Field Type: Text
- Required: Yes
- Formatting: No formatting
- 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.
- Field Label: Movie Score
- Field Name: movie_score
- Field Type: Number
- Required: Yes
- Minimum Value: 1
- Maximum Value: 10
- Step Size: 1
- 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.
- Field Label: Movie IMDb Link
- Field Name: movie_imdb_link
- Field Type: Text
- Field Instructions: Paste the full IMDb URL in here. e.g. http://www.imdb.com/title/tt2015381/
- Required: Yes
- Formatting: No formatting
- Kode di single.php atau single-postname.php denga nama single-movie.php
- <div class="reviews-meta">
- <ul>
- <li><?php _e('Year of release', 'movie'); ?>: <?php the_field('movie_year'); ?></li>
- <li><?php _e('Director', 'movie'); ?>: <?php the_field('movie_director'); ?></li>
- <li><?php _e('Rating', 'movie'); ?>: <?php the_field('movie_score'); ?>/10</li>
- <li><a href="<?php the_field('movie_imdb'); ?>" target="_blank"><?php _e('View on IMDb', 'movie'); ?></a></li>
- </ul>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement