我正在使用Avada主题 但是创建了一个自定义模板 在此,我想在每个帖子下方添加一个评论框。 但是comments_template()对我不起作用。 它没有显示帖子的评论框
am获得特定帖子的$get_cuurent=$_GET['id'];
ID
现在,我只想显示该帖子。
正在显示帖子,但评论框不起作用。
另外,我正在使用一个很小的HTML%编辑器来编辑内容。
<?php
/*
Template Name: Child template
*
* @package Avada
* @subpackage Templates
*/
?>
<?php get_header();
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
?>
<?php
$get_cuurent=$_GET['id'];
$cat_name= get_cat_name($get_cuurent);
$catobject = get_category($get_cuurent,false); // Get the Category object by the id of current category
$parentcat = $catobject->category_parent; // the id of the parent category
$args = array(
'parent' => $get_cuurent,
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => '',
'hide_empty' => false,
);
$cats = get_categories($args);
if(!empty($cats)){ //if parent category have child then it will show this
$categories = get_categories( $args );
foreach($categories as $cat) {
$cat_id = $cat->term_id; //get id post
if ( $cat_id == 1 ) // skip 'uncategorized'
continue; // skip 'uncategorized'
echo "<div class='col-md-6' style='text-align:center;'><img src='https://cdn2.hubspot.net/hubfs/306056/icons/start-362357.png' alt='img".$cat->name."'><h2>".$cat->name."</h2><a href='/wp/child-portal?id=".$cat_id."' class='".$cat->name.$cat_id."'>Click Here</a></div>";
}
}
else{ //if parent category have No child then it will show this
?>
<div id="postbox">
<section>
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12 post-pnl">
<form id="new_post" name="new_post" method="post">
<h2>POST</h2>
<!-- <input type="text" class="text-field col-lg-11 col-md-11 col-sm-10 col-11" > -->
<?php
$content = ' ';
$editor_id = 'newed';
$settings = array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => '',
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (supported on the front-end in WordPress 3.4)
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
); ?>
<?php wp_editor( $content, $editor_id, $settings ); ?>
<?php wp_nonce_field( 'wps-frontend-post' ); ?>
<p><label for="title">Topic</label><br />
<input type="text" id="title" value="Dermatology" tabindex="1" size="20" name="title" readonly/>
</p>
<p style="display: none;">
<label for="content">Post Content</label><br />
<textarea id="content" class="contenta" tabindex="3" name="content" cols="50" rows="6"></textarea>
</p>
<p align="right">
<input class="share-btn" type="submit" value="Share" tabindex="6" id="submit" name="submit" /></p>
</form>
<div class="getposterror"></div>
</div>
<div class="col-lg-8 col-md-8 col-sm-8 col-12 ">
<div class="col-lg-12 col-md-12 col-sm-12 col-12 user-pnl">
<div class="row">
<div class="user-box col-lg-10 col-md-10 col-sm-10 col-12">
<div class="row">
<div class="user-box col-lg-3 col-md-3 col-sm-3 col-10 user_img"><img src="images/user_img.png"></div>
<div class="user-box col-lg-5 col-md-5 col-sm-5 col-12">
<p>PUBLIC</p><h2>Dermatology</h2></div>
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-12 join"> <button class="join_btn">Share</button> </div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-12 sort_pnl none1">
<h2>Sort by:</h2>
<form >
<select class="select_menu col-lg-5">
<option>Most Recent Activity</option>
<option>Most Recent Activity1</option>
<option>Most Recent Activity2</option>
</select>
<div class="input-group col-lg-5">
<input type="text" class="form-control search_fild" placeholder="Search" name="search"><button class="btn btn-default search_btn" type="submit"><i class="fas fa-search"></i></button>
</div>
<select class="filter_menu col-lg-1">
<option class="filter_menu"><span><i class="fas fa-filter"></i> </option>
<option class="filter_menu"> <i class="fas fa-filter"></i> </option>
<option class="filter_menu"> <i class="fas fa-filter"></i> </option>
</select>
<button class="go_btn">Go</button>
</form>
</div>
<div class="comment_pnl col-lg-12 col-md-12 col-sm-12 col-12">
<?php
query_posts('cat='.$get_cuurent.'&showposts=10');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $current_id=get_the_ID(); ?>
<div class="gust_pnl col-lg-12 col-md-12 col-sm-12 col-12">
<div class="row">
<div class="col-lg-1 col-md-1 col-sm-1 col-2"><?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?> </div>
<div id="post-<?php echo $current_id ?>" class="comingpost col-lg-10 col-md-10 col-sm-10 col-10 none1"><h2><?php echo get_the_author(); ?> (<?php echo get_author_role(); ?>)</h2>
<p><strong><?php echo get_the_date(); ?> at <?php echo get_the_time(); ?> </strong></p>
</div>
</div>
<p class="text_pnl"><?php the_content();?></p>
<div class="lik_pnl">
<ul class="float-left">
<li >
<a href="#"><i class="far fa-comment-alt"></i> Comment</a>
</li>
<!-- <li>
<a href="#"><i class="far fa-share-square"></i> Share</a>
</li> -->
</ul>
<ul class="float-right">
<li >
<a href="#"><?php echo get_comments_number().' '; ?> comments </a>
</li>
<li >
<a href="#">| 29 views</a>
</li>
</ul>
</div>
</div>
<div class="clearfix"></div>
<div class="comment_box">
<?php comments_template(); ?>
<img src="images/client1.png"> <input type="text-field" class="col-lg-11 col-md-11 col-sm-11 col-11 text-field1" name="">
</div> <?php endwhile; else: ?>
<?php _e('No Posts Sorry ,For '.$cat_name); ?>
<?php endif; ?>
</section>
</div>
</div>
<?php
}
?>
<?php get_footer();
if ( !isset($_POST['title']) ) {
return;
}
// Check that the nonce was set and valid
if( !wp_verify_nonce($_POST['_wpnonce'], 'wps-frontend-post') ) {
echo '<span class="posterror">Did not save because your form seemed to be invalid. Sorry</span>';
return;
}
// Do some minor form validation to make sure there is content
if (strlen($_POST['title']) < 3) {
echo '<span class="posterror">Please enter a Topic. Topic must be at least three characters long.</span>';
return;
}
if (strlen($_POST['content']) < 10) {
echo '<span class="posterror">Please enter content more than 10 characters in length</span>';
return;
}
// Add the content of the form to $post as an array
$post = array(
'post_title' => 'Dermatology',
'post_content' => $_POST['content'],
'post_category' => array(
$parentcat,$get_cuurent),
'tags_input' => $_POST['post_tags'],
'post_status' => 'publish', // Could be: publish
'hide_empty' => false,
'post_type' => 'post' // Could be: `page` or your CPT
);
global $wp;
// get current url with query string.
$current_url = home_url( $wp->request );
// get the position where '/page.. ' text start.
$pos = strpos($current_url , '/page');
// remove string from the specific postion
$finalurl = substr($current_url,0,$pos);
$curnt=$current_url.'?id='.$get_cuurent;
if(wp_insert_post($post)){
header('Location: '.$curnt.'');
}
echo '<span class="posterror">Saved your post successfully! :)</span>';
/* Omit closing PHP tag to avoid "Headers already sent" issues. */
get_footer();