Browse code

주석 추가

Ikseon Kang authored on02/05/2020 15:57:18
Showing1 changed files
... ...
@@ -88,6 +88,10 @@ function add_my_story_fields($my_story_id, $my_story) {
88 88
   }
89 89
 }
90 90
 
91
+/*
92
+ * 주의) 아래의 템플릿이 인식되지 않거나, get_post_type() 이 빈칸으로 나올 경우
93
+ * 다른 테마로 활성화 한 다음. 다시 기존 테마로 활성화 하면 됨.
94
+ */
91 95
 function include_template_function($template_path) {
92 96
   if (get_post_type() == 'my_stories') {
93 97
     if (is_single()) {
Browse code

기본 기능 구현

Nepirity Corp authored on25/03/2018 09:20:13
Showing1 changed files
... ...
@@ -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
 ?>
Browse code

기본 파일 추가

Kang IkSeon authored on25/03/2018 08:38:51
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<?php
2
+/*
3
+ * Plugin Name: Wordpress Custom Post Type
4
+ * Description: 포스트 유형 추가 예제 플러그인
5
+ * Version:   1.0.0
6
+ * Author:    HiSEON
7
+ * Author URI:  https://hiseon.me/
8
+ */
9
+
10
+?>