User Tools

Site Tools


documentation:integration

Integration

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.

Step One

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. If you already have those lines then there is no need to add them again.

<?php
session_start();
?>

Step Two

Next you need to add the following lines inside the HTML head tag of the file. The first line declares the UTF-8 charset which means that foreign characters can be displayed. 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. The second line makes the page responsive to it can be viewed on mobiles and tablets. If you already have these lines then there is no need to add them again.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Step Three

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 folder is the name of the /upload/ folder that you renamed in step three of the installation guide. Make sure it ends in a forward slash.

There is never any need to edit the last line.

<?php
$cmtx_identifier = '1';
$cmtx_reference  = 'Page One';
$cmtx_folder     = '/upload/';
require($_SERVER['DOCUMENT_ROOT'] . $cmtx_folder . 'frontend/index.php');
?>

Many Pages

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.

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.

If you have only a few pages then manually type in a unique ID for each page.

HTML Pages

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.

  • The easiest solution is to add a line of code to a .htaccess file which will tell your server to execute any PHP code found in your HTML file(s) as such. With this method you don't need to alter your HTML file(s) at all. The .htaccess file can be in the same directory as the HTML file(s) or in any directory above it. It's usually best to put it in the root of your website. If you already have a .htaccess file there then just add it to that one. You can find an example of a .htaccess file inside the /upload/ folder. The line of code is:
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
  • Another option is to change the file extension from HTML to PHP. This can be done with your FTP application (e.g. FileZilla). Depending on how many files you have, this may take a while. A common concern with this method is the negative effect that it can have on your search engine listings. You can avoid this issue with the use of a permanent (301) redirect. This informs the search engines that the location of your page has changed so that they can update your URL and keep any page ranking. This process can take some time so it is important to keep the redirect alive for a period of time. Every page will need its own redirect. Again, this solution uses .htaccess and the line of code is as follows:
Redirect 301 /somepage.html http://www.example.com/somepage.php

Login Details

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_name = '';
$cmtx_email = '';
$cmtx_website = '';
$cmtx_town = '';
$cmtx_country = '';
$cmtx_state = '';

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 'Settings → Layout → Form'.

Troubleshooting

While the integration should go as intended if you follow the instructions correctly, there are certain errors that may appear.

  1. You may get a “headers already sent” error message. If so, try this FAQ: https://www.commentics.org/support/knowledgebase.php?article=30
  2. You might see unwanted symbols on your pages such as . This is because your website's template files responsible for displaying output may not be encoded correctly. To fix this open the files in Notepad++ and go to “Format → Convert to UTF-8 without BOM”.
  3. If you can't see any .htaccess files on your server, with FileZilla, go to “Server → Force showing hidden files”.
documentation/integration.txt · Last modified: 2016/11/17 19:33 by steven