Hi, in order to show the number of Discourse comments in a WordPress article without showing the comments themselves, we have added this simple code to single.php in our child theme:
<?php echo get_comments_number(); ?> comments
This will show the number of comments just fine, but how to make that this string links to the corresponding Discourse topic? I could not find a function, and I could not make {topic_url} work there either.
You can get the Discourse topic URL for a post with
get_post_meta( $post_id, 'discourse_permalink', true );
Something like this will work inside the loop (for example, in single.php)
<?php
$topic_url = get_post_meta( get_the_ID(), 'discourse_permalink', true );
$comments_number = get_comments_number();
switch ( $comments_number ) {
case 0:
$comment_link_text = 'Start the Conversation';
break;
case 1:
$comment_link_text = '1 Comment';
break;
default:
$comment_link_text = "$comments_number Comments";
}
?>
<a href="<?php echo esc_url( $topic_url ); ?>"><?php echo esc_html( $comment_link_text ); ?></a>
It works! Flawless. @simon you rock, also on Saturday night. Thank you very much.