Article

WordPress Plugin WP Sub Post

Oleh takien
</span>
<span class="st_h">&lt;/select&gt;&lt;/pre&gt;</span>
<span class="st_h">&lt;pre&gt;function subpost_template($content) {</span>
&nbsp;
<span class="st_h"> &nbsp; &nbsp;if(is_singular()) {</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp;remove_filter('</span>posts_where<span class="st_h">','</span>where_no_parent<span class="st_h">');</span>
<span class="st_h"> &nbsp; &nbsp;}</span>
&nbsp;
<span class="st_h"> &nbsp; &nbsp;$parentID = get_the_ID();</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; $childposts = get_posts(array(</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'</span>post_type<span class="st_h">' =&gt; '</span>post<span class="st_h">',</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'</span>numberposts<span class="st_h">' =&gt; -1,</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'</span>post_status<span class="st_h">' =&gt; '</span>publish<span class="st_h">',</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'</span>post_parent<span class="st_h">' =&gt; $parentID</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;));</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp;$subcontent = &quot;&quot;;</span>
<span class="st_h"> &nbsp; &nbsp;foreach($childposts as $childpost){</span>
<span class="st_h"> &nbsp; &nbsp; &nbsp; &nbsp;$subcontent .= &quot;&lt;/pre&gt;</span>
<span class="st_h">&lt;blockquote&gt;&quot;; $subcontent .= &quot;</span>
<span class="st_h">&lt;h3&gt;&quot;.$childpost-&gt;post_title.&quot;&lt;/h3&gt;</span>
<span class="st_h">&quot;; $subcontent .= $childpost-&gt;post_content; $subcontent .= '</span> <span class="sy0">&lt;</span>a href<span class="sy0">=</span><span class="st0">&quot;'.get_edit_post_link(<span class="es4">$childpost-&gt;ID</span>).'&quot;</span> rel<span class="sy0">=</span><span class="st0">&quot;nofollow&quot;</span><span class="sy0">&gt;</span>Edit<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span> <span class="st_h">'; $subcontent .= &quot;&lt;/blockquote&gt;</span>
<span class="st_h">&lt;pre&gt;</span>
<span class="st_h">&quot;;</span>
<span class="st_h"> &nbsp; &nbsp;}</span>
&nbsp;
<span class="st_h"> &nbsp; &nbsp;$content .= $subcontent;</span>
&nbsp;
<span class="st_h"> &nbsp; &nbsp;return $content;</span>
<span class="st_h">}</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
<div class="bwp-syntax-source">
<pre class="no-parse">&lt; ?php
/*
Plugin Name: WP Sub Post
Plugin URI: http://wordpress.org/#
Description: You can make a post is a child of another post.
Author: Takien
Version: 0.1 Alpha
Author URI: /
*/

////////////////////////////

class Walker_PostDropdown extends Walker {

var $tree_type = 'post';

var $db_fields = array ('parent' =&gt; 'post_parent', 'id' =&gt; 'ID');

function start_el(&amp;$output, $page, $depth, $args) {
$pad = str_repeat(' ', $depth * 3);

$output .= "\tID\"";
if ( $page-&gt;ID == $args['selected'] )
$output .= ' selected="selected"';
$output .= '&gt;';
$title = esc_html($page-&gt;post_title);
$output .= "$pad$title";
$output .= "\n";
}
}
/////////////
function &amp;wp_get_posts($args = '') {
global $wpdb;

$defaults = array(
'child_of' =&gt; 0, 'sort_order' =&gt; 'ASC',
'sort_column' =&gt; 'post_title', 'hierarchical' =&gt; 1,
'exclude' =&gt; '', 'include' =&gt; '',
'meta_key' =&gt; '', 'meta_value' =&gt; '',
'authors' =&gt; '', 'parent' =&gt; -1, 'exclude_tree' =&gt; '',
'number' =&gt; '', 'offset' =&gt; 0
);

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$number = (int) $number;
$offset = (int) $offset;

$cache = array();
$key = md5( serialize( compact(array_keys($defaults)) ) );
if ( $cache = wp_cache_get( 'wp_get_posts', 'posts' ) ) {
if ( is_array($cache) &amp;&amp; isset( $cache[ $key ] ) ) {
$pages = apply_filters('wp_get_posts', $cache[ $key ], $r );
return $pages;
}
}

if ( !is_array($cache) )
$cache = array();

$inclusions = '';
if ( !empty($include) ) {
$child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
$parent = -1;
$exclude = '';
$meta_key = '';
$meta_value = '';
$hierarchical = false;
$incpages = preg_split('/[\s,]+/',$include);
if ( count($incpages) ) {
foreach ( $incpages as $incpage ) {
if (empty($inclusions))
$inclusions = $wpdb-&gt;prepare(' AND ( ID = %d ', $incpage);
else
$inclusions .= $wpdb-&gt;prepare(' OR ID = %d ', $incpage);
}
}
}
if (!empty($inclusions))
$inclusions .= ')';

$exclusions = '';
if ( !empty($exclude) ) {
$expages = preg_split('/[\s,]+/',$exclude);
if ( count($expages) ) {
foreach ( $expages as $expage ) {
if (empty($exclusions))
$exclusions = $wpdb-&gt;prepare(' AND ( ID &lt;&gt; %d ', $expage);
else
$exclusions .= $wpdb-&gt;prepare(' AND ID &lt;&gt; %d ', $expage);
}
}
}
if (!empty($exclusions))
$exclusions .= ')';

$author_query = '';
if (!empty($authors)) {
$post_authors = preg_split('/[\s,]+/',$authors);

if ( count($post_authors) ) {
foreach ( $post_authors as $post_author ) {
//Do we have an author id or an author login?
if ( 0 == intval($post_author) ) {
$post_author = get_userdatabylogin($post_author);
if ( empty($post_author) )
continue;
if ( empty($post_author-&gt;ID) )
continue;
$post_author = $post_author-&gt;ID;
}

if ( '' == $author_query )
$author_query = $wpdb-&gt;prepare(' post_author = %d ', $post_author);
else
$author_query .= $wpdb-&gt;prepare(' OR post_author = %d ', $post_author);
}
if ( '' != $author_query )
$author_query = " AND ($author_query)";
}
}

$join = '';
$where = "$exclusions $inclusions ";
if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
$join = " LEFT JOIN $wpdb-&gt;postmeta ON ( $wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id )";

// meta_key and meta_value might be slashed
$meta_key = stripslashes($meta_key);
$meta_value = stripslashes($meta_value);
if ( ! empty( $meta_key ) )
$where .= $wpdb-&gt;prepare(" AND $wpdb-&gt;postmeta.meta_key = %s", $meta_key);
if ( ! empty( $meta_value ) )
$where .= $wpdb-&gt;prepare(" AND $wpdb-&gt;postmeta.meta_value = %s", $meta_value);

}

if ( $parent &gt;= 0 )
$where .= $wpdb-&gt;prepare(' AND post_parent = %d ', $parent);

$query = "SELECT * FROM $wpdb-&gt;posts $join WHERE (post_type = 'post' AND post_status = 'publish') $where ";
$query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;

if ( !empty($number) )
$query .= ' LIMIT ' . $offset . ',' . $number;

$pages = $wpdb-&gt;get_results($query);

if ( empty($pages) ) {
$pages = apply_filters('wp_get_posts', array(), $r);
return $pages;
}

// Sanitize before caching so it'll only get done once
$num_pages = count($pages);
for ($i = 0; $i &lt; $num_pages; $i++) {
$pages[$i] = sanitize_post($pages[$i], 'raw');
}

// Update cache.
update_page_cache($pages);

if ( $child_of || $hierarchical )
$pages = &amp; get_page_children($child_of, $pages);

if ( !empty($exclude_tree) ) {
$exclude = (int) $exclude_tree;
$children = get_page_children($exclude, $pages);
$excludes = array();
foreach ( $children as $child )
$excludes[] = $child-&gt;ID;
$excludes[] = $exclude;
$num_pages = count($pages);
for ( $i = 0; $i &lt; $num_pages; $i++ ) {
if ( in_array($pages[$i]-&gt;ID, $excludes) )
unset($pages[$i]);
}
}

$cache[ $key ] = $pages;
wp_cache_set( 'wp_get_posts', $cache, 'posts' );

$pages = apply_filters('wp_get_posts', $pages, $r);

return $pages;
}
//////////////

function walk_post_dropdown_tree() {
$args = func_get_args();
if ( empty($args[2]['walker']) ) // the user's options are the third parameter
$walker = new Walker_PostDropdown;
else
$walker = $args[2]['walker'];

return call_user_func_array(array(&amp;$walker, 'walk'), $args);
}

function wp_dropdown_posts($args = '') {
$defaults = array(
'depth' =&gt; 0, 'child_of' =&gt; 0,
'selected' =&gt; 0, 'echo' =&gt; 1,
'name' =&gt; 'page_id', 'show_option_none' =&gt; '', 'show_option_no_change' =&gt; '',
'option_none_value' =&gt; ''
);

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

$pages = wp_get_posts($r);
$output = '';
$name = esc_attr($name);

if ( ! empty($pages) ) {
$output = "&lt;select name="\"$name\""&gt;
&lt;option value="\"-1\""&gt;$show_option_no_change&lt;/option&gt;
&lt;option value="\"""&gt;$show_option_none&lt;/option&gt;\n";
&lt;/select&gt;
&lt;select name="\"$name\""&gt;}
&lt;/select&gt;

$output = apply_filters('wp_dropdown_pages', $output);

if ( $echo )
echo $output;

return $output;
}
/////////////////////////////

/* Use the admin_menu action to define the custom boxes */
add_action('admin_menu', 'myplugin_add_custom_box');

/* Use the save_post action to do something with the data entered */
add_action('save_post', 'myplugin_save_postdata');

/* Adds a custom section to the "advanced" Post and Page edit screens */
function myplugin_add_custom_box() {

if( function_exists( 'add_meta_box' )) {
add_meta_box( 'myplugin_sectionid', __( 'WP Sub Posts', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post', 'side','high' );
//add_meta_box( $id, $title, $callback, $page, $context, $priority );
add_meta_box( 'myplugin_sectionid', __( 'WP Sub Posts', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'page', 'advanced' );
} else {
add_action('dbx_post_advanced', 'myplugin_old_custom_box' );
add_action('dbx_page_advanced', 'myplugin_old_custom_box' );
}
}

function myplugin_inner_custom_box() {
echo '
&lt;pre&gt;&lt;select name="\"$name\""&gt;'; echo '
&lt;/select&gt;&lt;input id="myplugin_noncename" name="myplugin_noncename" type="hidden" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" /&gt;&lt;select name="\"$name\""&gt;'; ?&gt;
&lt;/select&gt;&lt;/pre&gt;
&lt;h5&gt;&lt;?php _e('Parent') ?&gt;&lt;/h5&gt;
&lt;pre&gt;&lt;label for="post_parent"&gt;Please select the parent of this post&lt;/label&gt;&lt;select name="\"$name\""&gt; &lt;?php $currentid = $_GET['post']; wp_dropdown_posts(array('exclude_tree' =&gt; $currentid, 'selected' =&gt; $post-&gt;post_parent, 'name' =&gt; 'parent_id', 'show_option_none' =&gt; __('Main Post (no parent)'), 'sort_column' =&gt; 'menu_order, post_title')); } /* Prints the edit form for pre-WordPress 2.5 post/page */ function myplugin_old_custom_box() { echo '
&lt;/select&gt;&lt;/pre&gt;
&lt;div class="dbx-b-ox-wrapper"&gt;' . "\n"; echo '
&lt;fieldset id="myplugin_fieldsetid" class="dbx-box"&gt;' . "\n"; echo '
&lt;div class="dbx-h-andle-wrapper"&gt;
&lt;h3 class="dbx-handle"&gt;' . __( 'WP Sub Posts', 'myplugin_textdomain' ) . "&lt;/h3&gt;
&lt;/div&gt;
"; echo '
&lt;div class="dbx-c-ontent-wrapper"&gt;
&lt;div class="dbx-content"&gt;'; // output editing form myplugin_inner_custom_box(); // end wrapper echo "&lt;/div&gt;
&lt;/div&gt;&lt;/fieldset&gt;
&lt;/div&gt;
&lt;pre&gt;&lt;select name="\"$name\""&gt;\n"; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want // to do anything if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['parent_id']; return $mydata; } add_filter('posts_where','where_no_parent'); add_filter ('the_content','subpost_template', 1, 2 ); function subpost_template($content) { if(is_singular) { remove_filter('posts_where','where_no_parent'); } echo $content; $idnya = get_the_ID(); $child = new WP_Query("post_type=post&amp;post_parent=".$idnya.""); while($child-&gt;have_posts()) : $child-&gt;the_post(); echo '
&lt;/select&gt;&lt;/pre&gt;
&lt;blockquote&gt;'; echo '
&lt;h3&gt;'; the_title(); echo '&lt;/h3&gt;
'; $childid = get_the_ID(); the_content(); edit_post_link('Edit','','',$childid); echo '&lt;/blockquote&gt;
&lt;pre&gt;&lt;select name="\"$name\""&gt;'; endwhile; wp_reset_query(); } function where_no_parent($where) { global $wpdb; $where .= " AND post_parent = 0"; return $where; } ?&gt; 


&lt;/select&gt;&lt;/pre&gt;
&lt;pre&gt;function subpost_template($content) {

    if(is_singular()) {
        remove_filter(‘posts_where’,‘where_no_parent’);
    }

    $parentID = get_the_ID();
       $childposts = get_posts(array(
                                ‘post_type’ =&gt; ‘post’,
                                ‘numberposts’ =&gt; -1,
                                ‘post_status’ =&gt; ‘publish’,
                                ‘post_parent’ =&gt; $parentID
                                ));
      $subcontent = “”;
    foreach($childposts as $childpost){
        $subcontent .= “&lt;/pre&gt;
&lt;blockquote&gt;”; $subcontent .= ”
&lt;h3&gt;“.$childpost-&gt;post_title.”&lt;/h3&gt;
“; $subcontent .= $childpost-&gt;post_content; $subcontent .= ‘ &lt;a href=”’.get_edit_post_link($childpost-&gt;ID).‘“ rel=“nofollow”&gt;Edit&lt;/a&gt; ’; $subcontent .= “&lt;/blockquote&gt;
&lt;pre&gt;
”;
    }

    $content .= $subcontent;

    return $content;
}</pre>
</div>
</div>
[php title=“wp_dropdown_posts()” block=“WP Dropdown Post”]</p>
<pre>global $post;
$currentid = $_GET[‘post’];
wp_dropdown_posts(array(‘exclude_tree’             =&gt; $currentid,
                            ‘selected’             =&gt; $post-&gt;post_parent,
                            ‘name’                 =&gt; ‘parent_id’,
                            ‘show_option_none’     =&gt; __(‘Main Post (no parent)’),
                            ‘sort_column’        =&gt; ‘menu_order, post_title’));</pre>
<p>

WP Sub Post is a wordpress plugin that allow you to make your wordpress post has a parent or child post.

Notes:

  • Child post is a real post that has a parent.
  • Child post only displayed on it’s parent post page or when parent page is displayed.
  • Child post can not be viewed individually.
  • Child post has all possibility like a normal post, such as attachment, custom fields etc.

Features:

  • Add/edit parent post directly from your post area.
  • No need to edit theme file.

Limitations:

  • No setting page
  • I don’t know about it’s compatibility.

Bugs:

  • Not compatible with my syntax highlight plugin 😀

[block title=”Screenshot”]

Plugin page:

New/Edit post page:

View Single Post:

RSS:

[/block]
Code:

Here is the code of this plugins…  Hahaha.. little bit messy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
< ?php
/*
Plugin Name: WP Sub Post
Plugin URI: http://wordpress.org/#
Description: You can make a post is a child of another post.
Author: Takien
Version: 0.1 Alpha
Author URI: /
*/
 
////////////////////////////
 
class Walker_PostDropdown extends Walker {
 
var $tree_type = 'post';
 
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
 
function start_el(&$output, $page, $depth, $args) {
$pad = str_repeat(' ', $depth * 3);
 
$output .= "\tID\"";
if ( $page->ID == $args['selected'] )
$output .= ' selected="selected"';
$output .= '>';
$title = esc_html($page->post_title);
$output .= "$pad$title";
$output .= "\n";
}
}
/////////////
function &wp_get_posts($args = '') {
global $wpdb;
 
$defaults = array(
'child_of' => 0, 'sort_order' => 'ASC',
'sort_column' => 'post_title', 'hierarchical' => 1,
'exclude' => '', 'include' => '',
'meta_key' => '', 'meta_value' => '',
'authors' => '', 'parent' => -1, 'exclude_tree' => '',
'number' => '', 'offset' => 0
);
 
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$number = (int) $number;
$offset = (int) $offset;
 
$cache = array();
$key = md5( serialize( compact(array_keys($defaults)) ) );
if ( $cache = wp_cache_get( 'wp_get_posts', 'posts' ) ) {
if ( is_array($cache) && isset( $cache[ $key ] ) ) {
$pages = apply_filters('wp_get_posts', $cache[ $key ], $r );
return $pages;
}
}
 
if ( !is_array($cache) )
$cache = array();
 
$inclusions = '';
if ( !empty($include) ) {
$child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
$parent = -1;
$exclude = '';
$meta_key = '';
$meta_value = '';
$hierarchical = false;
$incpages = preg_split('/[\s,]+/',$include);
if ( count($incpages) ) {
foreach ( $incpages as $incpage ) {
if (empty($inclusions))
$inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
else
$inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
}
}
}
if (!empty($inclusions))
$inclusions .= ')';
 
$exclusions = '';
if ( !empty($exclude) ) {
$expages = preg_split('/[\s,]+/',$exclude);
if ( count($expages) ) {
foreach ( $expages as $expage ) {
if (empty($exclusions))
$exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
else
$exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
}
}
}
if (!empty($exclusions))
$exclusions .= ')';
 
$author_query = '';
if (!empty($authors)) {
$post_authors = preg_split('/[\s,]+/',$authors);
 
if ( count($post_authors) ) {
foreach ( $post_authors as $post_author ) {
//Do we have an author id or an author login?
if ( 0 == intval($post_author) ) {
$post_author = get_userdatabylogin($post_author);
if ( empty($post_author) )
continue;
if ( empty($post_author->ID) )
continue;
$post_author = $post_author->ID;
}
 
if ( '' == $author_query )
$author_query = $wpdb->prepare(' post_author = %d ', $post_author);
else
$author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
}
if ( '' != $author_query )
$author_query = " AND ($author_query)";
}
}
 
$join = '';
$where = "$exclusions $inclusions ";
if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
$join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
 
// meta_key and meta_value might be slashed
$meta_key = stripslashes($meta_key);
$meta_value = stripslashes($meta_value);
if ( ! empty( $meta_key ) )
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
if ( ! empty( $meta_value ) )
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
 
}
 
if ( $parent >= 0 )
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
 
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'post' AND post_status = 'publish') $where ";
$query .= $author_query;
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;
 
if ( !empty($number) )
$query .= ' LIMIT ' . $offset . ',' . $number;
 
$pages = $wpdb->get_results($query);
 
if ( empty($pages) ) {
$pages = apply_filters('wp_get_posts', array(), $r);
return $pages;
}
 
// Sanitize before caching so it'll only get done once
$num_pages = count($pages);
for ($i = 0; $i < $num_pages; $i++) {
$pages[$i] = sanitize_post($pages[$i], 'raw');
}
 
// Update cache.
update_page_cache($pages);
 
if ( $child_of || $hierarchical )
$pages = & get_page_children($child_of, $pages);
 
if ( !empty($exclude_tree) ) {
$exclude = (int) $exclude_tree;
$children = get_page_children($exclude, $pages);
$excludes = array();
foreach ( $children as $child )
$excludes[] = $child->ID;
$excludes[] = $exclude;
$num_pages = count($pages);
for ( $i = 0; $i < $num_pages; $i++ ) {
if ( in_array($pages[$i]->ID, $excludes) )
unset($pages[$i]);
}
}
 
$cache[ $key ] = $pages;
wp_cache_set( 'wp_get_posts', $cache, 'posts' );
 
$pages = apply_filters('wp_get_posts', $pages, $r);
 
return $pages;
}
//////////////
 
function walk_post_dropdown_tree() {
$args = func_get_args();
if ( empty($args[2]['walker']) ) // the user's options are the third parameter
$walker = new Walker_PostDropdown;
else
$walker = $args[2]['walker'];
 
return call_user_func_array(array(&$walker, 'walk'), $args);
}
 
function wp_dropdown_posts($args = '') {
$defaults = array(
'depth' => 0, 'child_of' => 0,
'selected' => 0, 'echo' => 1,
'name' => 'page_id', 'show_option_none' => '', 'show_option_no_change' => '',
'option_none_value' => ''
);
 
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
 
$pages = wp_get_posts($r);
$output = '';
$name = esc_attr($name);
 
if ( ! empty($pages) ) {
$output = "<select name="\"$name\"">
<option value="\"-1\"">$show_option_no_change</option>
<option value="\""">$show_option_none</option>\n";
</select>
<select name="\"$name\"">}
</select>
 
$output = apply_filters('wp_dropdown_pages', $output);
 
if ( $echo )
echo $output;
 
return $output;
}
/////////////////////////////
 
/* Use the admin_menu action to define the custom boxes */
add_action('admin_menu', 'myplugin_add_custom_box');
 
/* Use the save_post action to do something with the data entered */
add_action('save_post', 'myplugin_save_postdata');
 
/* Adds a custom section to the "advanced" Post and Page edit screens */
function myplugin_add_custom_box() {
 
if( function_exists( 'add_meta_box' )) {
add_meta_box( 'myplugin_sectionid', __( 'WP Sub Posts', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post', 'side','high' );
//add_meta_box( $id, $title, $callback, $page, $context, $priority );
add_meta_box( 'myplugin_sectionid', __( 'WP Sub Posts', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'page', 'advanced' );
} else {
add_action('dbx_post_advanced', 'myplugin_old_custom_box' );
add_action('dbx_page_advanced', 'myplugin_old_custom_box' );
}
}
 
function myplugin_inner_custom_box() {
echo '
<pre><select name="\"$name\"">'; echo '
</select><input id="myplugin_noncename" name="myplugin_noncename" type="hidden" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" /><select name="\"$name\"">'; ?>
</select></pre>
<h5><?php _e('Parent') ?></h5>
<pre><label for="post_parent">Please select the parent of this post</label><select name="\"$name\""> <?php $currentid = $_GET['post']; wp_dropdown_posts(array('exclude_tree' => $currentid, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Post (no parent)'), 'sort_column' => 'menu_order, post_title')); } /* Prints the edit form for pre-WordPress 2.5 post/page */ function myplugin_old_custom_box() { echo '
</select></pre>
<div class="dbx-b-ox-wrapper">' . "\n"; echo '
<fieldset id="myplugin_fieldsetid" class="dbx-box">' . "\n"; echo '
<div class="dbx-h-andle-wrapper">
<h3 class="dbx-handle">' . __( 'WP Sub Posts', 'myplugin_textdomain' ) . "</h3>
</div>
"; echo '
<div class="dbx-c-ontent-wrapper">
<div class="dbx-content">'; // output editing form myplugin_inner_custom_box(); // end wrapper echo "</div>
</div></fieldset>
</div>
<pre><select name="\"$name\"">\n"; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want // to do anything if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['parent_id']; return $mydata; } add_filter('posts_where','where_no_parent'); add_filter ('the_content','subpost_template', 1, 2 ); function subpost_template($content) { if(is_singular) { remove_filter('posts_where','where_no_parent'); } echo $content; $idnya = get_the_ID(); $child = new WP_Query("post_type=post&post_parent=".$idnya.""); while($child->have_posts()) : $child->the_post(); echo '
</select></pre>
<blockquote>'; echo '
<h3>'; the_title(); echo '</h3>
'; $childid = get_the_ID(); the_content(); edit_post_link('Edit','','',$childid); echo '</blockquote>
<pre><select name="\"$name\"">'; endwhile; wp_reset_query(); } function where_no_parent($where) { global $wpdb; $where .= " AND post_parent = 0"; return $where; } ?> [/php]
</select><strong> Revision by <a href="http://www.kaskus.us/member.php?u=1202930">polvocdo</a></strong><select id="\"$name\"" name="\"$name\""> 1
</select><strong> Revision by <a href="http://www.kaskus.us/member.php?u=1202930">polvocdo</a></strong><select id="\"$name\"" name="\"$name\""> 1

Download

You can download alpha version of this plugin here Click here
This plugin is Alpha version, use it for testing purpose only. Any problem caused by this plugin is not my responsibility.

Demo:

See below:

Tulisan ini sudah berumur: 16 tahun 7 bulan 10 hari. Informasi di dalamnya mungkin sudah tidak relevan, tapi nilai historisnya sangat berharga, terutama bagi saya sebagai penulisnya.