I’m customizing a WordPress site and I want to put a link to the Discourse thread for a given post in a custom location in the HTML.
(Details: I’m customizing a LearnDash course site and the LearnDash “focus mode” gets rid of most of the standard WordPress layouts stuff, including comments. I’d like to use one of the LearnDash hooks to insert a link to the forum for a given lesson.)
Can anyone point me in the right direction for some wp-discourse code I can invoke to emit “link to thread” markup?
I don’t even need to load the list of discourse comments; I’d be content with a link to the discourse thread. But I can’t figure out how to use the wp-discourse code to get at that link :-/
I wound up doing this, just referencing the postmeta without using any of the WP-Discourse code.
I was never able to get anything to work involving listing comments… all the functions I could find seem to want to return HTML with a bunch of {placeholders} in it
You are right. That approach won’t work anymore. I think I can add a helper function to the plugin to make it easier to display the comments outside of the WordPress comments area. I need to make a small update to the plugin within the next couple of days, I’ll try to get a display_discourse_comments function added to the update. I’ll let you know when it’s available.
I’ve added a static helper function to the plugin that can be used to display comments without loading the Discourse comments template. The function is here: get_discourse_comments. It requires you to supply the post_id of the WordPress post that you want to display the comments for. Here’s a simple example of its use:
<?php
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$discourse_comments = DiscourseUtilities::get_discourse_comments( 859 );
echo $discourse_comments;
It displays the comments 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 settings on that page are respected.