Integrate Disqus comment in CodeIgniter 4

by Jairon Landa




In this tutorial, I will show you how to integrate Disqus comment for your CodeIgniter 4 project. Basic web project is included to demonstrate the Disqus comment.

Note: Internet connection is required to run Disqus comment. 

Github: https://github.com/Jaironlanda/CodeIgniter4-disqus

 

Step 1

Create a Disqus account. (https://disqus.com/profile/signup/)

create disqus account

 

Step 2

Register a forum for your website. https://disqus.com/admin/create/

Example:

register_forum

Next, select a plan. In this tutorial, i'm using Basic plan.

disqus basic plan

 

Step 3

Configure your Disqus. Select Settings at the admin navigation menu.

admin navigation menu

Enter appropriate detail about your website.

Example:

Disqus configuration

and Click Save

 

Step 4

Select Installation menu

install menu

For platform, select I don’t see my platform listed, install manually with Universal Code.

Example:

disqus platform

 

Step 5

Place the following code where Disqus to load.

Example:

PAGE_URL

Replace this with your URL blog. Example: 'http://example.com/id/12/my-blog-title/'

PAGE_IDENTIFIER

Page's unique identifier variable. For demonstration, I am using blog id. Example: '75'

 

Example project

This project I'm using CodeIgniter 4 + Bootstrap 4 and database MySQL. This is simple project to test Disqus comment for single blog post.

Project preview

CodeIgniter 4 integrate with Disqus comment

 

MySQL structure

CodeIgniter 4 MySQL structure

Query


CREATE TABLE `blog-disqus`.`blog` ( `blog_id` 
INT NOT NULL AUTO_INCREMENT ,  
 `title` VARCHAR(355) NOT NULL , 
 `slug` VARCHAR(355) NOT NULL , 
 `content` TEXT NOT NULL ,  
 `created_at` DATETIME NOT NULL ,  
 `updated_at` DATETIME NOT NULL ,   
 PRIMARY KEY  (`blog_id`)) 
ENGINE = InnoDB;

 

Front-end

Blog Index Preview

codeigniter 4 blog index

View app\Views\blog_index.php

This view will load all blog data from database.

 

View app\Views\blog_view.php

Preview

codeIgniter 4 blog view

As you can see, at line 42 I'm using current_url(). This helper is automatically loaded by the framework on every request.

 

Back-end

app\Models\BlogModel.php

app\Controllers\Home.php

 

Conclusion

You learn how to integrate Disqus comments in CodeIgniter 4 framework.

About Jairon Landa (@jaironlanda)
Jairon Landa

Backend and Frontend developer, a.k.a full-stack developer.

Kg Bundung, Tuaran

Recommended Posts