Mecha CMS

Mecha CMS blog and documentation.

Allow Comments on Specific Articles Only

Updated: Sunday, 07 August 2016

How to disable/enable comments on specific articles only?

Table of Content

Go to the Field manager, then create a new custom field called allow_comments:

  • Title: Allow Comments
  • Key: allow_comments
  • Type: Boolean
  • Scope: Article
  • Description: Allow visitors to commentate on this article.

Press the Create button. Now go to the Shield manager and edit your comments.php file.

Replace this line:

<?php if($config->comments->allow): ?>

with this:

<?php if($config->comments->allow && $article->fields->allow_comments): ?>

Save changes.

Or you could also do it in the opposite way:

  • Title: Disallow Comments
  • Key: disallow_comments
  • Type: Boolean
  • Scope: Article
  • Description: Disallow visitors to commentate on this article.

Then, in your comments.php file, replace the comments part I mentioned above with this:

<?php if($config->comments->allow && ! $article->fields->disallow_comments): ?>

Save changes.

Plugin

The plugin version of this tutorial is now available for Mecha 1.2.0 and above:

Download Latest Version

Donation and Email Subscription