Snippet · Mecha CMS

Code snippet collection for developers.

Mark Site Author’s Comments

Author: Taufik Nurrohman · 557 Views

Tweet

Set a unique style to the site author’s comments.

Requires comment extension and panel extension, and requires you to be logged in when creating a new comment. This snippet will add a status data to the $_POST storage with value 1.

if (Route::is('%*%/' . Extend::state('comment', 'path', '-comment')) && Request::is('post')) {
    if (Extend::exist('user') && Is::user()) {
        Request::set('post', 'status', 1);
    }
}

Then you can add this CSS to style the site author’s comments based on the default comments.php template:

.comment-status\:1 {
  color:#f00;
  border-left:4px solid #f00;
  padding-left:1em;
}

Which is based on this markup:

<li class="comment comment-status:<?php echo $comment->status; ?>">
  …
  …
</li>

3 Comments

  • Alexander Liebrecht

    Hi Taufik,
    To which file must the first code snippet be inserted?

    I would like to try it with me.

    • Taufik Nurrohman

      You don’t need to do anything if you are using the normal shield. I’ve added this snippet as a feature of the normal shield from the start. What you have to do is log in into the panel before you make a comment.

  • Alexander Liebrecht

    Now I understand it. If I am logged in, the comment of the admins are marked. Very good!