Horje
Enable comments to be added to a non-blog page - Wordpress Solution
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

Solution - 1

Yes, its posible. and this is an answer on your question. How to enable its quite different question! =)


Solution - 2

The call to the comments template is not put in the loop; it's put immediately after the loop. Look in the WP default theme page.php 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 wherever you'd like the comments and comment form to appear. Then, check your theme folder for your comments.php 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 comments.php 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


Solution - 3

Yes it's possible to have comments on a page. Wherever you want the comment form (as usual in the loop): Page.php

<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&amp;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 rel="nofollow" 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>


Solution - 4

Hello, Add this before your loop ( ENDWHILE ), 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 rel="nofollow" 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>



Solution - 5

1. Open your theme page.php file and add this lines before end of the loop ():

<?php
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 &#8220;<?php the_title(); ?>&#8221;</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 rel="nofollow" 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 rel="nofollow" href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a rel="nofollow" href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</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(); ?>

-->

ID); ?> 2. Go to Admin panel -> Pages -> Edit Page -> scroll down to Discussion panel and add tick to "Allow Comments". That's all !





Wordpress

Related
Autofocus+ - Wordpress Solution Autofocus+ - Wordpress Solution
Function to truncate comment text on home page. - Wordpress Solution Function to truncate comment text on home page. - Wordpress Solution
pagination with custom query with permalinks in functions.php - Wordpress Solution pagination with custom query with permalinks in functions.php - Wordpress Solution
Title showing up in body of post - Wordpress Solution Title showing up in body of post - Wordpress Solution
WP Admin White Screen - Wordpress Solution WP Admin White Screen - Wordpress Solution

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7