Code Update WP Sub Post
This post is a child post of WordPress Plugin WP Sub Post. To view the parent post, please click here.
There are some changes to the WP Sub Post:
- Fixed/Added, now child post can be viewed as a single post, with link to the Parent Post instead of displaying blank post with ‘Post not found’ title.
- Added, CSS class and id to the blockquote of the child post. It would be useful to make a link like http://example.com/parentpost.html#childpostXXX. while XXX is your child post ID.
Two functions that are changed subpost_template() and where_no_parent()
WP Sub Post
[raw]<pre>
function subpost_template($content) {
global $post;
$parentID = get_the_ID();
$childposts = get_posts(array(
'post_type' => 'post',
'numberposts' => -1,
'post_status' => 'publish',
'post_parent' => $parentID
));
$subcontent = "";
foreach($childposts as $childpost){
$subcontent .= "
<blockquote class=\"sub_post\" id=\"subpost_".$childpost->ID."\">";
$subcontent .= "
<h3>".$childpost->post_title."</h3>
";
$subcontent .= $childpost->post_content;
$subcontent .= '
<p class="postmetadata"><small>This sub post was added on: '.date('l, dS F, Y',strtotime($childpost->post_date)).' <a href="'.get_edit_post_link($childpost->ID).'" rel="nofollow">Edit</a></small>
';
$subcontent .= "</blockquote>
";
}
if($post->post_parent !== 0) {
$parent_info = '
<blockquote>This post is a child post of <strong>'.get_the_title($post->post_parent).'</strong>. To view the parent post, please <a href="'.get_permalink($post->post_parent).'">click here.</a></blockquote>
';
$content = $parent_info.$content;
}
$content .= $subcontent;
return $content;
}
function where_no_parent($where) {
global $wpdb;
if(!is_single()) {
$where .= " AND post_parent = 0";
}
else {
$where .= " AND post_type = 'post'";
}
return $where;
}
</pre>
<p>[/raw] Incoming search terms:
- wp sub post
- wordpress subpost
- <?php $parent = $post->id; while($parent) { $theparent = $parent; $parentpost = get_post($parent); $parent = $parentpost->post_parent;
- code post di wp
- wordpress post and subpost
- wordpress post subcontent
