I'm trying to build a debates-like system.
It will work like this:
A page will display the post with a countdown timer, so user will be able to submit comment till a specific period of time. (this will be the first page users will see)
All the comments submitted in that period of time will be displayed in a child page so there the users will be able to see all the comments.
And the other page will display some stats from the comments page like best comments(based on votes), poll results from a plugin shortcode.
All three pages will contain the same post ( the title, the content).
This is how I'm thinking to approach this: As long as the countdown plugin have the option to display other URL after the time is over I can replace the first page after the countdown is over with the page containing the poll results.
So by creating three pages in a parent-child relationship this can work.
Briefly, each of them will have different additional content ( first page will have a comments section where users will submit a comment, the other page will contain the comments submitted in the first one, and the third one will contain informations from the comments page like the poll results and best comments and also will replace the first page after the countdown is over.)
The first page will be the single-{myCPT}.php.
Second page which will be a child of the first page getting the comments from it. I will create this first from the dashboard assign it as a child to the first page and use a template for it something like page-{'slug'}.php Third page the same but of course with a different template.
I was thinking a lot and this seems the only solution.
Is this the way to go ? Or It can be done in a much easier way ? LATER EDIT: I've modified the cpt with my name and now I'm getting this:
Fatal error: Call to undefined function wpse121567_get_cpt_hierarchy()
SNIPPET FROM MY single-cpt.php:
<div id="content" class="span9" role="main">
<?php if ( 'debate-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'inc/post-format/single', get_post_format() );
endwhile; endif;
}
// Child CPT
else if ( 'debate-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
// Grandchild CPT
else if ( 'debate-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
?>
<?php
$enable_rtl = of_get_option('enable_rtl', false);
if(!of_get_option('disable_pagination')){
if($enable_rtl){
$next_post = get_adjacent_post( false, '', true );
$prev_post = get_adjacent_post( false, '', false );
}else{
$next_post = get_adjacent_post( false, '', false );
$prev_post = get_adjacent_post( false, '', true );
}
?>
<?php
}
// show related posts by tag
if(!of_get_option('disable_related_posts')){
get_template_part( 'inc/related-posts' );
}
// If comments are open or we have at least one comment, load up the default comment template provided by Wordpress
if ( comments_open() )
comments_template( '', true );
}else{ // Well, if there are no posts to display and loop through, let's apologize to the reader (also your 404 error) ?>
<article class="post error">
<h1 class="404"><?php _e('Page not found', 'outbox'); ?></h1>
</article>
<?php } // OK, I think that takes care of both scenarios (having a post or not having a post to show) ?>
</div><!-- #content .site-content -->
single-{cpt}.php
in this case?