To use Ajax Comment System in your website follow these simple steps:
Include the CSS
<link rel="stylesheet" href="assets/css/vendor/bootstrap.css">
<link rel="stylesheet" href="assets/css/vendor/prism-okaidia.css">
<link rel="stylesheet" href="assets/css/comments.css">
Note:
If you don't use Bootstrap, include
bootstrap-custom.css
instead ofbootstrap.css
.
By doing so, the Bootstrap CSS will be isolated to the comments and won't conflict with your CSS.
Include the JavaScript
<script src="assets/js/vendor/jquery.js"></script>
<script src="assets/js/vendor/bootstrap.js"></script>
<script src="assets/js/bundle.js"></script>
The bundle.js
files is meant to be used in production, when testing or if you want to make changes, you should include these files:
<script src="assets/js/vendor/jquery.timeago.js"></script>
<script src="assets/js/vendor/autosize.js"></script>
<script src="assets/js/vendor/prism.js"></script>
<script src="assets/js/vendor/tmpl.js"></script>
<script src="assets/js/comments.js"></script>
Start the Session
If your website doesn't already have the session started, add this on the first line in your file (before outputting anything):
<?php session_start(); ?>
Include the Init File
<?php require __DIR__.'/comments/start.php'; ?>
Display the Comments
<?php Comments::render('my_page_id'); ?>
The Comments::render
method has one argument, which is a page identifier. Can be a number or string.
If you don't pass the page identifier, the current url will be used as an identifier.
Auth Buttons
To display the Log in and Sign up buttons paste the following snippet before displaying the comments:
<?php if (Auth::check()) { ?>
Logged as <a href="user.php"><?php echo Auth::user()->name; ?></a> |
<a href="user.php?action=logout">Logout</a>
<?php } else { ?>
<a href="user.php?action=login">Log in</a> |
<a href="user.php?action=signup">Sign up</a>
<?php } ?>