Once the script installation is complete you will need to add the script to your page(s). To do this you will need at least one file to add the script to. You may already have this file existing somewhere on your site, perhaps it's an article that you have written or some other useful information. If you don't then you will need to create one now. Once you know which file to add the script to, move onto the steps below. The file should ideally be a PHP file. If it's a HTML file then read the 'HTML Pages' section below.
In the package you downloaded, there is an example.php file which you can look at.
The first step for integration is to add the following to the very first line of the file. It is necessary for session-dependant features to work. By first line, this means even above the <!DOCTYPE html> and <html> lines.
<?php session_start(); ?>
Next you need to add the following line inside the HTML head tag of the file. It declares the UTF-8 charset which means that foreign characters can be displayed. If you already have this line then there is no need to add it again. If you have the 'ISO-8859-1' charset tag, or any other charset tag, please remove it and replace it with this UTF-8 one.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
The last part is the code to actually display the comments and the comment form. This should be added somewhere in your HTML body tag, wherever you want the comments to be shown.
The identifier can contain any value. Just make sure that it's unique to each page that you add the script to.
The reference should be a short descriptive term of the page. It is shown to your visitors. Using the heading of the page is a good idea.
The path stores the server path (not the URL path) from the file to the /upload/ folder. If your file is in the root of your website, you can leave this line alone. If in a directory then add ../ to the start so it is “../upload/”. If in a directory in a directory it should be “../../upload/” and so on.
There is never any need to edit the other lines.
<?php $cmtx_identifier = '1'; $cmtx_reference = 'Page One'; $cmtx_path = 'upload/'; require $cmtx_path . 'includes/commentics.php'; //don't edit this line ?>
If you want to add the script to many pages then you won't want to do this manually. Fortunately, as of Commentics v1.4, there are several built-in features to make this easier. By entering keywords into the $cmtx_identifier and $cmtx_reference variables the script can perform actions to replace these keywords with dynamic information.
Please note that these keywords should only be used as a last resort. If you have many pages then there's a good chance that you have a database-driven website where each page already has a unique ID which you can supply to Commentics. Using this ID is always best.
The keywords that can be entered for the Identifier value are:
The keywords that can be entered for the Reference value are:
Of course, you can also supply your own dynamic information such as $cmtx_identifier = $_GET['name'];
Sometimes a website URL will contain query parameters that determine the content of the page, such as site.com/page.php?id=5
URLs might also contain extra query parameters that are not important, such as site.com/page.php?id=5&order=asc
To remove unwanted parameters, you can add a variable called 'cmtx_parameters' to the top of your integration code. For its value, simply list your important parameters separated by a comma and then the script will remove any parameters not in the list. For example:
<?php $cmtx_parameters = 'id'; $cmtx_identifier = 'cmtx_url'; $cmtx_reference = 'Page One'; $cmtx_path = 'upload/'; require $cmtx_path . 'includes/commentics.php'; //don't edit this line ?>
An example list could be $cmtx_parameters = 'id,category,language';
By leaving the $cmtx_parameters value empty or by typing “none” the script will remove all URL query parameters.
Note that this only works in conjunction with the cmtx_url keyword.
Most of the code for Commentics is written in PHP, meaning that for integration a normal HTML file won't work. Fortunately there are (at least) a couple of options available.
AddHandler application/x-httpd-php5 .html .htm .shtml
# If your host is 'Go Daddy', or the above does not work, try this line instead AddHandler x-httpd-php5-cgi .html .htm .shtml
Redirect 301 /somepage.html http://www.example.com/somepage.php
If your site uses a login system, you may want to pass some of this information to Commentics so that your visitors won't need to fill in the form. Fortunately, as of Commentics v2.0, this is possible by adding a few lines to the top of your integration code.
$cmtx_set_name_value = ''; $cmtx_set_email_value = ''; $cmtx_set_website_value = ''; $cmtx_set_town_value = ''; $cmtx_set_country_value = '';
After adding the above lines, you may want to disable or hide the fields to make it quicker and simpler for your visitors to complete the form. As of Commentics v2.4, this can be done by changing the settings in Layout → Form → States.
The topic, (displayed at the top right of the comments section), is retrieved from the page's reference. If you would like to change the topic, but not the page reference, simply add this line to the top of your integration code.
$cmtx_set_topic = '';
While the integration should go as intended if you follow the instructions correctly, there are certain errors that may appear.