-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE REQUEST] Disable comments per-post #794
Comments
I have begun to implement a way to disable comments per post using the theme rather than do a core hack. The approach is similar to how a table of contents is implemented, but rather than add: <!--toc--> to a post on which you want a table of contents, you add: <!--no-comments--> to posts you don't want to have comments. You then need to modify the appropriate code in your theme. In twenty-sixteen's <?php if (disqus()): ?>
<?php echo disqus($p->title, $p->url) ?>
<?php endif; ?>
<?php if (disqus_count()): ?>
<?php echo disqus_count() ?>
<?php endif; ?>
<?php if (facebook() || disqus()): ?>
<div class="comments-area" id="comments">
<h2 class="comments-title"><?php echo i18n('Comments');?> “<?php echo $p->title;?>”</h2>
<?php if (facebook()): ?>
<div class="fb-comments" data-href="<?php echo $p->url ?>" data-numposts="<?php echo config('fb.num') ?>" data-colorscheme="<?php echo config('fb.color') ?>"></div>
<?php endif; ?>
<?php if (disqus()): ?>
<div id="disqus_thread"></div>
<?php endif; ?>
</div>
<?php endif; ?> to: <?php $no_comments = explode('<!--no-comments-->', $post->body); ?>
<?php if (!isset($no_comments['1'])): ?>
<?php if (disqus()): ?>
<?php echo disqus($p->title, $p->url) ?>
<?php endif; ?>
<?php if (disqus_count()): ?>
<?php echo disqus_count() ?>
<?php endif; ?>
<?php if (facebook() || disqus()): ?>
<div class="comments-area" id="comments">
<h2 class="comments-title"><?php echo i18n('Comments');?> “<?php echo $p->title;?>”</h2>
<?php if (facebook()): ?>
<div class="fb-comments" data-href="<?php echo $p->url ?>" data-numposts="<?php echo config('fb.num') ?>" data-colorscheme="<?php echo config('fb.color') ?>"></div>
<?php endif; ?>
<?php if (disqus()): ?>
<div id="disqus_thread"></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?> Basically, I wrapped the comment insertion code between: <?php $no_comments = explode('<!--no-comments-->', $post->body); ?>
<?php if (!isset($no_comments['1'])): ?> and <?php endif; ?> So far, this seems to be working fine. I have yet to address how I want to handle comment counts in the post info and whether I want to add a "Comments have been disabled for this post" notification where comments would normally go. But overall this seems to be a workable approach until (if ever!) the feature is added to the core. |
I'm a bit late to propose some kind of a workaround, but was doing other things with htmly, as you could see in other "issues". Basically htmly lacks adding some sort of custom fields for content management in admin panel, although such functionality is available for templates. Would be great if @danpros enabled discussions here, or implemented a simple forum on htmly's website to discuss things related to htmly rather than spamming issues section. |
@Joduai I have other personal projects that really needs attention so I've been pretty inactive here lately. Already enable the discussion. |
@KuJoe Since this is something that impacts the content text, I'm wondering whether it might be better to add a "No comments" icon to the text editor toolbar instead. A dropdown or checkbox is nice, but it could lead to the following scenario: User disables comments, which adds the Putting it in the toolbar makes it behave like the TOC button, which while not ideal is arguably more consistent. The bigger question is whether the |
The implementation I coded does remove it when it's enabled so that shouldn't be an issue. I considered adding it to the toolbar but since this is more a setting than a content addition I felt it would be better added to the rest of the post settings rather than the body of the post. I'm happy to change it though if everybody likes the toolbar method better. EDIT: And just to expand on this a bit so you better understand how the add/edit post functions work, when you "edit" an existing post it actually recreates the whole thing each time so it's not actually editing the content file. In this case every time the file is saved it checks if comments are enabled or disabled and either includes or excludes the tag depending on the setting when the submit button is pressed so it's a much easier task than parsing existing text and trying to remove it. If it wasn't so simple then your method would 100% be the easiest and safest implementation and I wouldn't have bothered going this route. 😉 |
Comments may not be desired on all blog posts.
Assuming you have enabled comments in HTMLy, it would be great if you could disable them for some posts. Disqus (and possibly other comment providers) lets you close comments per-post, but visible code injected by Disqus remains.
Many blogging platforms have a simple checkbox on a post's editing page that lets you disable comments for that post.
The text was updated successfully, but these errors were encountered: