| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,30 @@ |
| 1 |
+<?php get_header(); ?> |
|
| 2 |
+<div id="primary"> |
|
| 3 |
+ <div id="content" role="main"> |
|
| 4 |
+ <?php $mypost = array( 'post_type' => 'my_stories', ); |
|
| 5 |
+ $loop = new WP_Query( $mypost ); ?> |
|
| 6 |
+ |
|
| 7 |
+ <?php while ( $loop->have_posts() ) : $loop->the_post();?> |
|
| 8 |
+ <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> |
|
| 9 |
+ <header class="entry-header"> |
|
| 10 |
+ <div style="float: top; margin: 10px"> |
|
| 11 |
+ <?php the_post_thumbnail( array( 100, 100 ) ); ?> |
|
| 12 |
+ </div> |
|
| 13 |
+ |
|
| 14 |
+ <strong>Title: </strong><?php the_title(); ?><br /> |
|
| 15 |
+ <strong>Memo: </strong> |
|
| 16 |
+ <?php echo esc_html( get_post_meta( get_the_ID(), 'story_memo', true ) ); ?> |
|
| 17 |
+ <br /> |
|
| 18 |
+ <strong>Rating: </strong> |
|
| 19 |
+ <?= intval( get_post_meta( get_the_ID(), 'story_rating', true ) ); ?> |
|
| 20 |
+ </header> |
|
| 21 |
+ <div class="entry-content"> |
|
| 22 |
+ <?php the_content(); ?> |
|
| 23 |
+ </div> |
|
| 24 |
+ <hr/> |
|
| 25 |
+ </article> |
|
| 26 |
+ <?php endwhile; ?> |
|
| 27 |
+ </div> |
|
| 28 |
+</div> |
|
| 29 |
+<?php wp_reset_query(); ?> |
|
| 30 |
+<?php get_footer(); ?> |
| ... | ... |
@@ -7,4 +7,100 @@ |
| 7 | 7 |
* Author URI: https://hiseon.me/ |
| 8 | 8 |
*/ |
| 9 | 9 |
|
| 10 |
+function create_my_story() {
|
|
| 11 |
+ register_post_type('my_stories',
|
|
| 12 |
+ array( |
|
| 13 |
+ 'labels' => array( |
|
| 14 |
+ 'name' => 'My Stories', |
|
| 15 |
+ 'singular_name' => 'My Story', |
|
| 16 |
+ 'add_new' => 'Add New', |
|
| 17 |
+ 'add_new_item' => 'Add New My Story', |
|
| 18 |
+ 'edit' => 'Edit', |
|
| 19 |
+ 'edit_item' => 'Edit My Story', |
|
| 20 |
+ 'new_item' => 'New My Story', |
|
| 21 |
+ 'view' => 'View', |
|
| 22 |
+ 'view_item' => 'View My Story', |
|
| 23 |
+ 'search_items' => 'Search My Stories', |
|
| 24 |
+ 'not_found' => 'No My Stories found', |
|
| 25 |
+ 'not_found_in_trash' => 'No My Stories found in Trash', |
|
| 26 |
+ 'parent' => 'Parent My Story' |
|
| 27 |
+ ), |
|
| 28 |
+ |
|
| 29 |
+ 'public' => true, |
|
| 30 |
+ |
|
| 31 |
+ 'menu_position' => 15, |
|
| 32 |
+ 'supports' => array('title', 'editor'),
|
|
| 33 |
+ /* 'supports' => array('title', 'editor', 'comments', 'thumbnail', 'custom-fields'), */
|
|
| 34 |
+ 'taxonomies' => array(''),
|
|
| 35 |
+ 'menu_icon' => 'dashicons-smiley', |
|
| 36 |
+ 'has_archive' => true |
|
| 37 |
+ ) |
|
| 38 |
+ ); |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+add_action('init', 'create_my_story');
|
|
| 42 |
+ |
|
| 43 |
+function my_admin() {
|
|
| 44 |
+ add_meta_box('my_story_meta_box',
|
|
| 45 |
+ 'My Story Details', |
|
| 46 |
+ 'display_my_story_meta_box', |
|
| 47 |
+ 'my_stories', 'normal', 'high' |
|
| 48 |
+ ); |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+add_action('admin_init', 'my_admin');
|
|
| 52 |
+ |
|
| 53 |
+function display_my_story_meta_box($my_story) {
|
|
| 54 |
+ $story_memo = esc_html(get_post_meta($my_story->ID, 'story_memo', true)); |
|
| 55 |
+ $story_rating = intval(get_post_meta($my_story->ID, 'story_rating', true)); |
|
| 56 |
+?> |
|
| 57 |
+ <table> |
|
| 58 |
+ <tr> |
|
| 59 |
+ <td style="width: 100%">Story Memo</td> |
|
| 60 |
+ <td><input type="text" size="80" name="my_story_memo" value="<?php echo $story_memo; ?>" /></td> |
|
| 61 |
+ </tr> |
|
| 62 |
+ <tr> |
|
| 63 |
+ <td style="width: 150px">Story Rating</td> |
|
| 64 |
+ <td> |
|
| 65 |
+ <select style="width: 100px" name="my_story_rating"> |
|
| 66 |
+ <?php for ($rating = 5; $rating >= 1; $rating --) { ?>
|
|
| 67 |
+ <option value="<?php echo $rating; ?>" <?php echo selected($rating, $story_rating); ?>> |
|
| 68 |
+ <?php echo $rating; ?> stars |
|
| 69 |
+ </option> |
|
| 70 |
+ <?php } ?> |
|
| 71 |
+ </select> |
|
| 72 |
+ </td> |
|
| 73 |
+ </tr> |
|
| 74 |
+ </table> |
|
| 75 |
+<?php |
|
| 76 |
+} |
|
| 77 |
+ |
|
| 78 |
+add_action('save_post', 'add_my_story_fields', 10, 2);
|
|
| 79 |
+ |
|
| 80 |
+function add_my_story_fields($my_story_id, $my_story) {
|
|
| 81 |
+ if ($my_story->post_type == 'my_stories') {
|
|
| 82 |
+ if (isset($_POST['my_story_memo']) && $_POST['my_story_memo'] != '') {
|
|
| 83 |
+ update_post_meta($my_story_id, 'story_memo', $_POST['my_story_memo']); |
|
| 84 |
+ } |
|
| 85 |
+ if (isset($_POST['my_story_rating']) && $_POST['my_story_rating'] != '') {
|
|
| 86 |
+ update_post_meta($my_story_id, 'story_rating', $_POST['my_story_rating']); |
|
| 87 |
+ } |
|
| 88 |
+ } |
|
| 89 |
+} |
|
| 90 |
+ |
|
| 91 |
+function include_template_function($template_path) {
|
|
| 92 |
+ if (get_post_type() == 'my_stories') {
|
|
| 93 |
+ if (is_single()) {
|
|
| 94 |
+ if ($theme_file = locate_template(array ('single-my_stories.php'))) {
|
|
| 95 |
+ $template_path = $theme_file; |
|
| 96 |
+ } else {
|
|
| 97 |
+ $template_path = plugin_dir_path(__FILE__) . '/single-my_stories.php'; |
|
| 98 |
+ } |
|
| 99 |
+ } |
|
| 100 |
+ } |
|
| 101 |
+ return $template_path; |
|
| 102 |
+} |
|
| 103 |
+ |
|
| 104 |
+add_filter('template_include', 'include_template_function', 1);
|
|
| 105 |
+ |
|
| 10 | 106 |
?> |