Hi
I would like people to be able to leave comments on this page http://dougalmacdonald.com/?page_id=912 with most recent comment displayed at the top.
Is this possible....?
Thanks in advance and warm regards.
Sarah
Oleg Butuzov answers:
Yes, its posible.
and this is an answer on your question. How to enable its quite different question! =)
SarahK comments:
You've been such a help, thank you.
Especially when, as yet, I can't get any of the more useful suggestions to work.
Oleg Butuzov comments:
You want working suggestion? how about Sliven code? its a good code =)
Oleg Butuzov comments:
well not good.
ok here is how you can do that.
1) open template that you use for page (you want to anable comments)
2) insert somewhere at bottom or a place where you want to show comments a code
<?php comments_template(); ?>
3) and last - check is comments allowed to that page.
and yeah - thats shortest answer in this tread.
and its a workable code too =)
fair enough?
Darrin Boutote answers:
The call to the comments template is <em>not</em> put in the loop; it's put immediately after the loop. Look in the WP default theme <strong>page.php</strong> template for an example of where the call to the comments theme goes.
To add comments to a specific page, open that page's template and add <strong><?php comments_template(); ?></strong> wherever you'd like the comments and comment form to appear.
Then, check your theme folder for your <strong>comments.php</strong> template file. If you don't have one, check the default theme folder for an example. To list comments with the most recent ones first, open the <strong>comments.php</strong> file and look for this section:
<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>
Change:
<?php wp_list_comments(); ?>
to:
<?php wp_list_comments(array('reverse_top_level' => 'true', 'reverse_children' => 'true')); ?>
And in the Dashboard, open the page in question and check "Allow Comments" under the "Discussion" metabox.
You can also check out the Codex page on listing comments here: http://codex.wordpress.org/Template_Tags/wp_list_comments
Chris Lee answers:
Yes it's possible to have comments on a page.
Wherever you want the comment form (as usual in the loop):
<strong>Page.php</strong>
<div id="comments-template"><?php comments_template(); ?></div>
Add this for Recent Comments:
<div class="Recent-comments">
<h2>Recent Comments</h2>
<ul>
<?php
$comments = get_comments('number=10&status=approve');
$true_comment_count = 0;
foreach($comments as $comment) :
?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
<?php $true_comment_count = $true_comment_count +1; ?>
<?php $comm_title = get_the_title($comment->comment_post_ID);?>
<?php $comm_link = get_comment_link($comment->comment_ID);?>
<?php $comm_comm_temp = get_comment($comment->comment_ID,ARRAY_A);?>
<?php $comm_content = $comm_comm_temp['comment_content'];?>
<li><span class="comments-author">< ?php echo($comment->comment_author)?></span> on <a href="<?php echo($comm_link)?>" title="< ?php comment_excerpt(); ?>"> < ?php echo $comm_title?> </a>
</li>
<?php } ?>
<?php if($true_comment_count == 5) {break;} ?>
<?php endforeach;?>
</ul>
</div>
Rashad Aliyev answers:
Hello,
Add this before your loop ( ENDWHILE ), <?php comments_template(); ?>
I gave you an example.
<?php get_header(); ?>
<div id="container">
<div id="left-div">
<div id="left-inside">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!--Start Post-->
<div class="post-wrapper">
<h1 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?>
</a></h1>
<div style="clear: both;"></div>
<?php the_content(); ?>
</div>
<div class="post-wrapper">
<?php comments_template(); ?>
</div>
<?php endwhile; ?>
<!--End Post-->
<?php else : ?>
<!--If no results are found-->
<h1>No Results Found</h1>
<p>The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.</p>
<!--End if no results are found-->
<?php endif; ?>
</div>
</div>
<!--Begin Sidebar-->
<?php get_sidebar(); ?>
<!--End Sidebar-->
<!--Begin Footer-->
<?php get_footer(); ?>
<!--End Footer-->
</body>
</html>
Rashad Aliyev comments:
I gave you a comment template from your page and however If you want to show your recent comments,
than use this code:
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\n<ul>";
foreach ($comments as $comment) {
$output .= "\n<li>".strip_tags($comment->comment_author)
.":" . "<a href=\"" . get_permalink($comment->ID) .
"#comment-" . $comment->comment_ID . "\" title=\"on " .
$comment->post_title . "\">" . strip_tags($comment->com_excerpt)
."</a></li>";
}
$output .= "\n</ul>";
$output .= $post_HTML;
echo $output;?>
Rashad Aliyev comments:
Ass you see There're
ORDER BY comment_date_gmt DESC
LIMIT 10";
DESC sort of your comments you can use if you want ascending order you can change it to ASC.
Now Limit 10, also you can change it what you want. If you have any question you can contact with me.
Best regards,
Svilen Popov answers:
1. Open your theme <strong>page.php</strong> file and add this lines before end of the loop <em>(<?php endwhile; else: ?>)</em>:
<?php
</small></p>-->
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
?>
<?php if ( have_comments() ) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<div class="navigation">
<div class="alignleft"><?php previous_comments_link() ?></div>
<div class="alignright"><?php next_comments_link() ?></div>
</div>
<ol class="commentlist">
<?php wp_list_comments('reverse_top_level=1');; ?>
</ol>
<div class="navigation">
<div class="alignleft"><?php previous_comments_link() ?></div>
<div class="alignright"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ( comments_open() ) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( comments_open() ) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
<div class="cancel-comment-reply">
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
<p>You must be <a href="<?php echo wp_login_url( get_permalink() ); ?>">logged in</a> to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( is_user_logged_in() ) : ?>
<p>Logged in as <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">Log out »</a></p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?>
<p><textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; ?>
</code>
2. Go to <strong>Admin panel</strong> -> <strong>Pages</strong> -> <strong>Edit Page</strong> -> scroll down to Discussion panel and add tick to "<strong>Allow Comments</strong>".
That's all !