Play with page comments

Display each comments of the page

If you haven’t removed or deleted it, you only have to include:

<?php $this->includeSnippet('comment-form') ?>

then customise the snippet to fit your CSS template. If you do have this snippet you will need to continue reading…

It is almost like the children() method, but instead of getting pages, you will get comments:

    <?php $comments = $this->comments(); ?>
    <ol class="comments">
    <?php foreach ($comments as $comment): ?>
      <li class="comment">
        <p><?php echo $comment->body(); ?></p>
        <p> - <?php echo $comment->name(); ?> 
          <small class="comment-date"><?php echo $comment->date(); ?></small>
        </p>
      </li>
    <?php endforeach; // comments ?>
    </ol>

here is the list of what you can display from a comment:

  • name() the name of the author of the comment
  • email() the email of the author of the comment
  • link() the website link of the author of the comment
  • body() the comment (this comment is HTML safe)
  • date(['%a, %e %b %Y']) the date, you can change the format to it

Display the number of comments on the page

The easy way is :

<?php echo $this->commentsCount(); ?> comment(s)

This example is more complex, because it will add “s” to the word “comment” if the comment count is zero or greater than one:

<?php echo $num_comments = $this->commentsCount(); ?>
	comment<?php if ($num_comments != 1) { echo 's'; } ?>

Display the form for adding a comment on a page

If you haven’t removed or deleted it, you only have to include:

<?php $this->includeSnippet('comment-form'); ?>

If you have done this terrible thing of deleting it, here is the form again:

<form action="<?php echo $this->url() ?>" method="post" id="comment_form"> 
    <p>
        <input class="comment-form-name" type="text" name="comment[author_name]" id="comment_form_name" value="" size="22" /> 
        <label for="comment_form_name"> name (require)</label>
    </p>
    <p>
        <input class="comment-form-email" type="text" name="comment[author_email]" id="comment_form_email" value="" size="22" /> 
        <label for="comment_form_email"> email (will not be published) (required)</label>
    </p>
    <p>
        <input class="comment-form-link" type="text" name="comment[author_link]" id="comment_form_link" value="" size="22" /> 
        <label for="comment_form_link"> website</label>
    </p>
    <p>
        <textarea class="comment-form-body" id="comment_form_body" name="comment[body]" cols="100%" rows="10"></textarea>
    </p>
    <p>
        <input class="comment-form-submit" type="submit" name="commit-comment" id="comment_form_submit" value="Submit comment" />
    </p>
</form>

Frog CMS Demo

Public front end website click here
Administration backend click here

Opensource.com admin login info:
login: admin
password: demo123

Help us!

There is no profit here. The more we raise the longer we can keep things going and the better it will get.

Click here to lend your support to: Frog CMS and make a donation at www.pledgie.com !