WP Discourse를 설정하여 Discourse의 댓글을 표시하기

You can use Discourse as a comments system for Wordpress. The Commenting features are dependent on the publishing features, so you need publishing to be set up for commenting to work. If you’ve set up publishing and are ready to set up commenting, watch this short video, or follow the instructions below.

Next Step

Once you’ve set up commenting, you may want to check out the following topics


Instructions

Setting up Commenting

To have Discourse comments show up on your WordPress site, you must select the Enable Discourse Comments setting. When enabled, you will see two options. The Display comments option will load a Comment template for each WordPress post that has been published to Discourse. This template will display Discourse comments beneath the WordPress posts. The Display a link to the comments option will load a comments template that displays a link to the associated Discourse topic underneath the published posts. The number of replies to the topic will be displayed in the link, but no replies will be displayed on WordPress.

Both of these commenting options work by loading comment templates for the WordPress posts. This means that they will only work if comments are enabled for the post. If you would like to enable comments for all posts, but not have any historical WordPress comments be displayed for posts that have not been published to Discourse, enable the Remove WordPress Comments Template setting.

Settings

Here are some short descriptions on what the other commenting settings do. If you’re still unsure about any of the settings reply to this topic and ask for further clarification.

Load Comments With Ajax

This setting is used to load comments from the Wordpress client, instead of loading them from the server. This is useful if page caching is preventing fresh comments from being loaded on your site.

Load Comment CSS

This setting loads a stylesheet that fixes issues with Discourse oneboxes and quotes when they are displayed on WordPress.

Show Existing WP Comments

Select this setting to also show existing WordPress comments for posts that have also been published to Discourse, select the setting.

Existing Comments Heading

If you are showing existing comments, this setting will add a heading above the WordPress comments.

Selective Import Settings

There are a number of settings which allow you to selectively import comments. These should be self-explanatory. The default values for each of these are a good place to start, so only change these if you have a reason to

  • Max Visible Comments
  • Min Number of Replies
  • Min Score of Posts
  • Min Trust Level
  • Bypass Trust Level Score
  • Only Import Moderator-Liked
Custom Datetime Format

This setting formats the date that is displayed for each Discourse comment that appears on your WordPress site. Start with the default value. If you find you want to change the date format, click on the link in the setting’s description for details on how to do that.

Cache Comment HTML

This setting can be used to improve performance. Caching the Comment HTML reduces the number of requests made to Discourse. It’s associated setting Clear Cached Comment HTML should be self explanatory.

Verbose Comment Logs

Enabling this will log all successful retrievals of comments from Discourse, in addition to errors (the default).

Sync Comment Data Webhook

Enabling the Sync Comment Data wehbook in the “Webhooks” setting panel can greatly reduce the number of API requests made from WordPress to Discourse. Before enabling the webhook

  1. visit the Discourse URL provided in the setting’s description (http://forum.example.com/admin/api/web_hooks.)

  2. Click the ‘New Webhook’ button and fill out the form

    • In the Payload URL field, enter the URL that is provided in the description of the WP Discourse Sync Comment Data field. It will be something like this, except using your WordPress site’s URL: https://wp-discourse.dev/wp-json/wp-discourse/v1/update-topic-content.

    • Make sure the Content Type field is set to application/json.

    • In the Secret input, enter a string of text, at least 12 characters long. Then copy this same key into the WP Discourse Webhook Secret Key setting..

    • In the ‘Which events should trigger this webhook?’ box, make sure that ‘Post Event’ is selected.

    • Use the Triggered Categories field if you only publish posts from WordPress to specific categories. That way, your WordPress site will not need to process webhook requests for topics that don’t have an associated Discourse post.

    • Leave the Check TLS certificate of payload url setting enabled.

    Finally, enable the ‘Active’ checkbox, and click create. When the webhook has saved, click the Go to events button.

  3. Back on WordPress, make sure that you have entered the webhook secret from Discourse into the Webhook Secret Key field and enable the Sync Comment Data webhook setting. Then save the options.

The Discourse webhook should now be working. You should check it by clicking the webhook’s Ping button on Discourse (found at /admin/api/web_hooks/:webhook_id/events.) Make sure that pinging the webhook is returning a status code of 200.

Adjusting the comments_number sync period for WordPress archive pages

To get the correct number of Discourse comments for a post, the plugin needs to periodically make an HTTP request to Discourse to get the current comments number. On single pages this period is set to be no more often than every 10 minutes. For archive pages the period is set to no more than once every 24 hours. The reason for this is to avoid making multiple request to Discourse every time an archive page is accessed.

If you still find that the plugin is making too many request to Discourse when displaying your site’s archive pages, you can adjust the archive_page_sync_period by hooking into the 'discourse_archive_page_sync_period' filter. You do that by adding something like this to your theme’s functions.php file:

add_filter( 'discourse_archive_page_sync_period', 'my_namespace_archive_page_sync_period' );
function my_namespace_archive_page_sync_period( $sync_period ) {
  // This will change to sync_period for archived posts to once a week.
  return WEEK_IN_SECONDS;
}

If you find that the plugin is not making enough requests to Discourse to retrieve the current comment numbers for archive pages, you can add something like this to your theme’s functions.php file. This will set the archive_page_sync_period to 10 minutes.
Note: on a busy site this could place a heavy load on your server.

add_filter( 'discourse_archive_page_sync_period', 'my_namespace_archive_page_sync_period' );
function my_namespace_archive_page_sync_period( $sync_period ) {
  // This will change to sync_period for archived posts to once a week.
  return 10 * MINUTE_IN_SECONDS;
}

Display comments without loading the WordPress comments template

The WP Discourse plugin uses the WordPress comments template to load Discourse comments. If your theme is not loading the comments template, you can display comments with the static get_discourse_comments helper function. That function requires you to supply the id of the WordPress post that you want to display comments for. Here’s a simple example of its use:

use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$discourse_comments = DiscourseUtilities::get_discourse_comments(859);
echo $discourse_comments;

Comments will be displayed in the same way as they are displayed if you select the
Enable Discourse Comments/Display Comments option (found on the plugin’s Comment Settings tab.) When this function is used, the value of that setting is ignored, but all other Comment settings are respected.

Troubleshooting

The most common issue with Discourse comments is that they may not show up instantly after the post is made on Discourse. This delay is intentional as the plugin tries to reduce the number of requests it needs to make to Discourse. Making a request every time the page is loaded will slow down your site. If you’re not seeing comments appear instantly wait 10 minutes before refreshing the page again.

Issues with the comment number when displaying both Discourse and WordPress comments

The wp-discourse plugin uses the WordPress get_comments_number filter hook so that the number of Discourse comments that have been created for a post can be displayed throughout your theme. This creates a conflict when both Discourse and WordPress comments are being displayed for a post. The plugin is able to resolve that conflict in most places. One place where it can’t be resolved is in the comment title that WordPress themes often display at the head of the comment section. This is the section that begins with something like “2 thoughts on…”

The easiest way to do this is to add a rule to your theme’s css file.

.discourse-comments-area ~ .comments-area .comments-title  {
	display: none;
}
8개의 좋아요

@angus 정말 잘 만든 가이드와 영상 감사합니다. 플러그인을 구현했는데, 댓글 기능에서 막혀 있습니다. 두 가지 질문/문제가 있습니다:

  • discourse에서 wordpress의 공유 게시물에 답글을 게시하면 wordpress의 답글 수는 변경되지만, 실제 댓글이 표시되지 않습니다.
  • 사용자가 discourse를 통해서만 답글을 달 수 있도록 wordpress의 댓글 기능을 끄고 싶은데, 가능한가요?

아래는 우리가 확인한 내용입니다. 이 '1’개의 답글은 discourse에서 온 것이지만, 답글 본문은 보이지 않습니다:

CC: @Abdelrahman_MoHamed

안녕하세요 @Jacob_Peebles,

위 가이드를 따랐다면 다음으로 확인할 것은 테마입니다. 혹시 블록 테마(Block Theme)를 사용 중인가요? 그렇다면 다음 내용을 참고해 주세요:

네, 워드프레스에서 댓글 기능을 끄면 됩니다.

  1. 대시보드에서 설정 > 토론을 선택하세요.
  2. ‘새 게시물에 대한 댓글 작성 허용’ 옆의 체크박스를 해제하세요.
  3. 설정 저장 버튼을 클릭하세요.
1개의 좋아요

@angus - 완벽하게 작동해서 정말 좋습니다! 네, Apparently 우리가 ‘블록’ 에디터를 사용하고 있는 것 같습니다. 여기에서 기능이 정상적으로 작동하는 것을 확인할 수 있습니다:

유일하게 이상한 부분은 스타일/폰트가 discourse 댓글로 캐스케이드되지 않는다는 점입니다. 이것이 단순히 우리 테마의 문제인지, 아니면 별도로 언급할 가치가 있는 것인지 확실하지 않습니다.

다시 한번 감사합니다.

죄송합니다, 스크린샷도 첨부합니다.

제이콥, 잘 작동한다고 해서 기쁩니다.

직접 댓글 스타일링을 추가해야 합니다. 각 테마마다 스타일링 방식이 다르기 때문에 디스코urses 댓글은 기본적으로 매우 가볍게 스타일링되어 있습니다. 제이콥의 경우, 다음과 같은 기본적인 스타일링이 문제를 해결하는 데 도움이 될 것입니다.

ol.comment-list {
    list-style: none;
    padding: 0;
}

img.avatar.photo.avatar-default {
    height: 40px;
    width: 40px;
}

.comment-author.vcard {
   display: flex;
   align-items: center;
   gap: 1em;
}

1개의 좋아요

훌륭해요 @angus

@angus 님, 안녕하세요.

훌륭한 플러그인과 도움이 되는 설명에 감사드립니다!

저는 Discourse를 WordPress 웹사이트에 통합했으며, 연결도 정상적으로 되어 있습니다.
WP 사이트에서 게시물을 생성하면 Discourse에서 새로운 Topic으로 가져오는 것을 확인했습니다. 정말 좋습니다!

하지만 Discourse에서는 게시물의 초기 내용(예: hello world 등)만 발췌문으로 표시되며, WP 게시물의 내용을 수정한 후에도 Discourse의 Topic 내용이 업데이트되지 않습니다. ‘Show Full Post’ 버튼을 클릭해야만 내용 변경이 반영됩니다. 즉, 게시물의 전체 내용을 발췌문이 아닌 전체 텍스트로 표시하도록 설정을 변경할 수 없습니다. 그렇게 설정하면 Discourse Topic에서 해당 버튼이 사라지고, 업데이트되기 전의 초기 내용만 표시됩니다. 제가 무슨 말을 하고 있는지 이해가 되실지 모르겠습니다.


(전체 내용 표시로 설정된 경우)


(발췌문만 표시하도록 설정된 경우의 발췌문)


(전체 텍스트를 표시하기 위한 버튼을 클릭했을 때의 모습으로, 이는 WP 게시물에 있는 내용과 동일합니다)

그리고 또한, Discourse에서 해당 Topic에 대한 답글로 작성된 댓글은 WP의 게시물 아래에 표시되지 않습니다. 저는 댓글 기능을 활성화했으며, 블록 에디터가 아닌 Astra 테마를 사용 중입니다. 이 문제를 해결하기 위해 무엇을 해야 할지 모르겠습니다.

이 두 가지 사항에 대해 조언을 주시면 감사하겠습니다. 감사합니다!

안녕하세요 @Clo, 플러그인을 사용해 주셔서 감사합니다. 게시물을 게시할 때 기대하는 이상적인 상태를 좀 더 자세히 설명해 주실 수 있을까요? “사용자 스토리” 형식으로 정리해 주시면 감사하겠습니다. 또한 댓글에 대해 질문이 있는데, 현재 사용 중인 사이트에서 WordPress 댓글 기능이 활성화되어 있나요?

@angus 님 안녕하세요

드디어 Discourse 사이트에서 WP 사이트로 댓글이 가져와진 것 같습니다. 시간이 좀 걸렸네요. 감사합니다!

다만, Discourse에서 새 주제가 생성될 때마다 플러그인이 WP에 새 게시물을 자동으로 생성할 수 있는지 궁금합니다. 아니면 반대 방향(WP에서 Discourse로)으로만 가능한가요?

그것은 WordPress와 Discourse 양쪽에 추가적인 맞춤형 플러그인이 있어야만 가능합니다. WP Discourse 플러그인 자체는 이를 위해 설계되지 않았습니다.

정말 감사합니다, 도움이 많이 됩니다.
훌륭한 플러그인입니다!

1개의 좋아요