Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Allowing Comments on a Page using Karma WP Theme WordPress

  • SOLVED

Hi all,

First posting - I hope you can help :)

I’m trying to create a new page template that would allow comments to be added to select Pages on my site. The site uses the Karma WP Theme. I was originally following the advice provided on this page: http://inntaonlinesolutions.com/add-comments-pages-wordpress/ but have since found that the Karma theme does "fancy things" so I don't think that solution will work (and, in fact, it did not, see here: http://www.flowmotionlabs.com/test-comment-page)

So, what I need is someone to give me the code that needs to go into my new template file called page-with-comments.php, which is essentially a copy of the Karma page template, page.php, with 1 additional line <?php comments_template(); ?>.

I will provide what I believe are the supporting files from Karma as well.

============================
page-with-comments.php:

<?php

/*

Template Name: Page with Comments

*/

?>

<?php get_header(); ?>
</div><!-- header-area -->
</div><!-- end rays -->
</div><!-- end header-holder -->
</div><!-- end header -->

<?php truethemes_before_main_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<div id="main">

<?php get_template_part('theme-template-part-tools','childtheme'); ?>

<div class="main-holder">
<div id="content" class="content_full_width">
<?php if(have_posts()) : while(have_posts()) : the_post(); the_content(); truethemes_link_pages(); endwhile; endif; ?>

<?php comments_template(); ?>

</div><!-- end content -->
</div><!-- end main-holder -->
</div><!-- main-area -->

<?php get_footer(); ?>



==========================
As far as I can tell, one or more of the following files may provide a hint as to what I need in the page-with-comments.php file.

Single Post (single.php):

<?php get_header(); ?>
<?php
/*
* @since version 1.0
* modified @since 2.6 development
* use global variable $ttso
*/
global $ttso;
$ka_blogtitle = $ttso->ka_blogtitle;
$ka_searchbar = $ttso->ka_searchbar;
$ka_crumbs = $ttso->ka_crumbs;
$show_tools_panel = $ttso->ka_tools_panel;
?>
</div><!-- header-area -->
</div><!-- end rays -->
</div><!-- end header-holder -->
</div><!-- end header -->

<?php truethemes_before_main_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<div id="main">
<div class="main-area">

<?php
/*
* Check to display or hide tools panel
* @since version 2.6 development
*/
if($show_tools_panel != 'false'):
?>

<div class="tools">
<div class="holder">
<div class="frame">

<?php truethemes_before_article_title_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<h1><?php echo $ka_blogtitle; ?></h1>
<?php if ($ka_searchbar == "true"){
//parent theme uses searchform.php
//create a file in child theme named searchform-childtheme.php to overwrite.
get_template_part('searchform','childtheme');
} else {}
?>
<?php if ($ka_crumbs == "true"){ $bc = new simple_breadcrumb;} else {} ?>

<?php truethemes_after_searchform_hook();// action hook, see truethemes_framework/global/hooks.php ?>

</div><!-- end frame -->
</div><!-- end holder -->
</div><!-- end tools -->

<?php endif; //end show tools panel check @since version 2.6 dev ?>

<div class="main-holder">
<div id="content" class="content_blog">
<?php get_template_part('theme-template-part-content-blog-single','childtheme'); ?>
</div><!-- end content -->

<div id="sidebar" class="sidebar_blog">
<?php dynamic_sidebar("Blog Sidebar"); ?>
</div><!-- end sidebar -->
</div><!-- end main-holder -->
</div><!-- main-area -->
<?php get_footer(); ?>


======================
theme-template-part-content-blog-single.php:


<?php
/*
* This file is a template part
* produces WordPress Loop for use in single.php
* moved to theme root from contents folder @since version 2.6
*
*/

$ka_blogtitle = get_option('ka_blogtitle');
$ka_searchbar = get_option('ka_searchbar');
$ka_crumbs = get_option('ka_crumbs');
$ka_blogbutton = get_option('ka_blogbutton');
$ka_blogauthor = get_option('ka_blogauthor');
$ka_related_posts = get_option('ka_related_posts');
$ka_related_posts_title = get_option('ka_related_posts_title');
$ka_related_posts_count = get_option('ka_related_posts_count');
$ka_posted_by = get_option('ka_posted_by');
$ka_post_date = get_option('ka_post_date');
if ($ka_post_date != "false"){ $ka_post_date_result = 'style="background:none !important;"';}else{$ka_post_date_result = '';}
$ka_dragshare = get_option('ka_dragshare');
$blog_image_frame = get_option('ka_blog_image_frame');

if (have_posts()) : while (have_posts()) : the_post();
//retrieve all post meta of posts in the loop.

$linkpost = get_post_meta($post->ID, "_jcycle_url_value", $single = true);
$external_image_url = get_post_meta($post->ID,'truethemes_external_image_url',true);
$video_url = get_post_meta($post->ID,'truethemes_video_url',true);
$permalink = get_permalink($post->ID);
//prepare to get image
$thumb = get_post_thumbnail_id();
$image_width = 538;
$image_height = 218;

//use truethemes image croping script, function moved to truethemes_framework/global/basic.php
$image_src = truethemes_crop_image($thumb,$external_image_url,$image_width,$image_height);
?>



<div class="single_blog_wrap">
<div class="post_title">

<?php truethemes_begin_single_post_title_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<h2><?php the_title(); ?></h2>
<?php if ($ka_posted_by != "true") {?><p class="posted-by-text"><span><?php _e('Posted by:', 'truethemes_localize') ?></span> <?php the_author_posts_link(); ?></p><?php }?>

<?php truethemes_end_single_post_title_hook();// action hook, see truethemes_framework/global/hooks.php ?>

</div><!-- end post_title -->


<div class="post_content" <?php echo $ka_post_date_result; ?>>

<?php truethemes_begin_single_post_content_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<?php
//function to generate internal image, external image or video for content-blog.php, content-blog-single.php, and archive.php
//please find it in truethemes_framework/global/basic.php

$html = truethemes_generate_blog_image($image_src,$image_width,$image_height,$blog_image_frame,$linkpost,$permalink,$video_url);

echo $html;
?>


<?php

the_content();

if(function_exists('truethemes_link_pages')){
//Will always use this function for <!--nextpage-->
//function modified from wp_link_pages() to provide more style class
//so that we can style the page links.
truethemes_link_pages();
}else{
//WordPress default page number links function for <!--nextpage-->
//This is for theme check plugin requirement.
//Do not remove this function checks, but comments can be removed..
wp_link_pages();
}

?>

<?php if(function_exists('selfserv_shareaholic')) { selfserv_shareaholic(); } ?>

<?php if ($ka_post_date != "true"): ?>
<div class="post_date">
<span class="day"><?php the_time('j'); ?></span>
<br />
<span class="month"><?php echo strtoupper(get_the_time('M')); ?></span>
</div><!-- end post_date -->

<div class="post_comments">
<a href="<?php echo the_permalink().'#post-comments'; ?>"><span><?php comments_number('0', '1', '%'); ?></span></a>
</div><!-- end post_comments -->
<?php endif; ?>


<?php if ($ka_dragshare == "true"){ echo "<a class='post_share sharelink_small' href='$permalink' data-gal='prettySociable'>Share</a>"; }?>



<?php if ($ka_related_posts == "true"){
echo '<br class="clear" /><br class="clear" />';
echo do_shortcode("[related_posts_content limit=\"".$ka_related_posts_count."\" title=\"".$ka_related_posts_title."\"]");

}?>


<?php truethemes_end_single_post_content_hook();// action hook, see truethemes_framework/global/hooks.php ?>

</div><!-- end post_content -->



<div class="post_footer">

<?php truethemes_begin_single_post_footer_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<div class="post_cats"><p><span><?php _e('Categories:', 'truethemes_localize') ?></span> <?php the_category(', '); ?></p></div><!-- end post_cats -->

<?php if (get_the_tags()) : ?>
<div class="post_tags"><p><span><?php _e('Tags:', 'truethemes_localize') ?></span> <?php the_tags('', ', '); ?></p></div><!-- end post_tags -->
<?php endif; ?>

<?php truethemes_end_single_post_footer_hook();// action hook, see truethemes_framework/global/hooks.php ?>

</div><!-- end post_footer -->




<?php if ($ka_blogauthor == "true"){ ?>
<div class="comment-wrap" id="about-author-wrap">
<div class="comment-content">
<div class="comment-gravatar"><?php echo get_avatar(get_the_author_meta('email'),$size='80',$default=get_template_directory_uri().'/images/_global/default-grav.jpg' ); ?>
</div><!-- end comment-gravatar -->

<div class="comment-text">
<p class="comment-author-about"><?php _e('About the Author:', 'truethemes_localize') ?></p>
<?php the_author_meta('description'); ?>
</div><!-- end comment-text -->

</div><!-- end comment-content -->
</div><!-- end comment-wrap -->
<?php } else {} ?>
</div><!-- end single_blog_wrap -->



<?php
/*
* Add check on whether to disable comments througout site.
* @since version 2.6 development.
*/
global $ttso;
$show_post_comments = $ttso->ka_post_comments;
if($show_post_comments !='false'):
comments_template('', true);
endif;
?>

<?php endwhile; else: ?>
<h2><?php _e('Nothing Found', 'truethemes_localize') ?></h2>
<p><?php _e('Sorry, it appears there is no content in this section.', 'truethemes_localize') ?></p>
<?php endif; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>


======================
comments.php:

<?php
// Prevent Comments page from being accessed directly
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thank You!');
// Prevent Comments page from being displayed if password protected
if ( post_password_required() ) { ?> <p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php return; } ?>





<?php // Formatted Comments Function
function Karma_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div class="comment-wrap">
<div class="comment-content" id="comment-<?php comment_ID(); ?>">
<div class="comment-gravatar"><?php echo get_avatar($comment,$size='60',$default=get_template_directory_uri().'/images/_global/default-grav.jpg' ); ?>
</div><!-- end comment-gravatar -->

<div class="comment-text">
<span class="comment-author"><?php comment_author_link() ?></span> &nbsp;<span class="comment-date"><?php comment_date('F j, Y'); ?></span><br />
<?php if ($comment->comment_approved == '0') : ?><?php _e('Your comment is awaiting moderation.','truethemes_localize') ?><?php endif; ?>
<?php comment_text() ?>
<?php comment_reply_link(array_merge( $args, array('reply_text' => '(reply)', 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?> <?php edit_comment_link(__('(edit)','truethemes_localize'),' ','') ?>
</div><!-- end comment-text -->
</div><!-- end comment-content -->
</div><!-- end comment-wrap -->
<?php }






function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li>
<span class="comment-author"><?php comment_author_link() ?></span> &nbsp;<span class="comment-date"><?php comment_date('F j, Y'); ?></span><br />
<?php } ?>
<?php if (have_comments()) : ?>
<?php $comment_count = count($comments_by_type['comment']); ($comment_count !== 1) ? $comment_txt = __('Comments','truethemes_localize') : $comment_txt = __('Comment','truethemes_localize');?>
<?php $trackback_count = count($comments_by_type['pings']); ($comment_count !== 1) ? $comment_txt_trackback = __('Trackbacks','truethemes_localize') : $comment_txt_trackback = __('Trackback','truethemes_localize');?>







<div class="tabs-area" id="blog-tabs">
<p class="comment-title">Discussion</p>
<ul class="tabset">
<li><a href="#tab-0" class="tab"><span><?php echo "<strong>".$comment_count."</strong> &nbsp;".$comment_txt; ?></span></a></li>
<li><a href="#tab-1" class="tab"><span><?php echo "<strong>".$trackback_count."</strong> &nbsp;".$comment_txt_trackback; ?></span></a></li>
</ul>
<div id="tab-0" class="blog-tab-box">
<?php if ( ! empty($comments_by_type['comment']) ) : ?>
<ol class="comment-ol" id="post-comments">
<?php wp_list_comments('callback=Karma_comments&type=comment'); ?>
</ol>


<!-- BEGIN COMMENTS PAGINATION -->
<div id="comments">
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<nav id="comment-nav-below">
<div class="nav-next"><?php paginate_comments_links(); ?></div>
</nav>
<?php endif; // check for comment navigation ?>
</div>
<!-- END COMMENT PAGINATION -->


<?php endif; ?>
<?php else : if ('open' == $post->comment_status) : else : endif; endif; ?>




<?php // Wordpress Coments Form
if ('open' == $post->comment_status) : ?>

<div id="respond">
<div class="comments-rss"><?php post_comments_feed_link(__('Subscribe to Comments','truethemes_localize')); ?></div><!-- end comments-rss -->
<h1 class="comment-title"><?php comment_form_title(__('Add a Comment','truethemes_localize'),__('Reply to %s','truethemes')); ?></h1>

<div class="comment-cancel"><?php cancel_comment_reply_link(); ?></div><!-- end comment-cancel -->


<?php if ( get_option('comment_registration') && !$user_ID) : ?>
<p>You must be<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>"> logged in</a> to post a comment.</p>
<?php else : ?>


<form method="post" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" id="commentform" class="ka-form">
<?php if ($user_ID) : ?>
<p class="logged"><?php _e('Logged in as','truethemes_localize'); ?> <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account"><?php _e('Log out &raquo','truethemes_localize'); ?></a></p>
<?php else : ?>
<p class="comment-input-wrap pad"><label class="comment-label" for="author"><?php _e('Name','truethemes_localize'); ?> <span class="mc_required">*</span></label>
<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" tabindex="1" class="comment-input" /></p
>
<p class="comment-input-wrap pad"><label class="comment-label" for="email"><?php _e('Email','truethemes_localize'); ?> <span class="mc_required">*</span></label>
<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" tabindex="2" class="comment-input comment-email" /></p>

<p class="comment-input-wrap"><label class="comment-label" for="url"><?php _e('Website','truethemes_localize'); ?></label>
<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" tabindex="3" class="comment-input comment-website" /></p>
<?php endif; ?>

<p class="comment-textarea-wrap"><label class="comment-label" for="comment"><?php _e('Your Comments','truethemes_localize'); ?></label><textarea name="comment" class="comment-textarea" tabindex="4" rows="5" cols="5" id="comment"></textarea></p>
<p><input type="submit" value="<?php _e('Add Comment','truethemes_localize'); ?>" id="ka-submit" /><?php comment_id_fields(); ?></p>
<p><?php do_action('comment_form', $post->ID); ?></p>
</form>
<?php endif; ?>
</div><!--end comment-response-->
<?php endif; ?>






<?php // Output Trackbacks
if (have_comments()) : ?>
</div>
<div id="tab-1" class="blog-tab-box">
<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<ol class="commentlist">
<?php wp_list_comments('callback=list_pings&type=pings'); ?>
</ol>
<?php endif; ?>
</div>
</div>
<?php else : if ('open' == $post->comment_status) : else : endif; endif; ?>


=================

I hope that's enough information. And that it's clearer to you than it is to me! Let me know if you need anything else.

To be clear, my preferred answer would be the code that I simply need to cut and paste into my page-with-comments.php file (and/or any supporting files).

All the best,
La.

Answers (2)

2012-07-08

Hai Bui answers:

Please try this:

<?php
/*
Template Name: Page with Comments
*/
?>
<?php get_header(); ?>
</div><!-- header-area -->
</div><!-- end rays -->
</div><!-- end header-holder -->
</div><!-- end header -->
<?php truethemes_before_main_hook();// action hook, see truethemes_framework/global/hooks.php ?>

<div id="main">
<?php get_template_part('theme-template-part-tools','childtheme'); ?>
<div class="main-holder">
<div id="content" class="content_full_width">
<?php if(have_posts()) : while(have_posts()) : the_post(); the_content(); truethemes_link_pages(); endwhile; endif; ?>
<?php
/*
* Add check on whether to disable comments througout site.
* @since version 2.6 development.
*/
global $ttso;
$show_post_comments = $ttso->ka_post_comments;
if($show_post_comments !='false'):
comments_template('', true);
endif;
?>

</div><!-- end content -->
</div><!-- end main-holder -->
</div><!-- main-area -->
<?php get_footer(); ?>


Remember that you need to check "Allow comments" for the page.


lw8 comments:

Hello Hai,

Thanks for the code!

I've put the code into page-with-comments.php, which is the template being used on this page: http://www.flowmotionlabs.com/test-comment-page

As you can see, it seems to have not made any difference.

You mentioned "Remember that you need to check "Allow comments" for the page." and I have checked but there does not seem to be such a setting on a *Page*. I've attached a screenshot of my Settings/Discussion panel, if that helps.

All the best,
La.