Howto show the topic id in Metadata of initial Post

AI-generated summary

The discussion revolves around displaying the Topic ID in the initial Post metadata of a specific category in Discourse. nstoecki42 initially tried to achieve this through configuration and a plugin but was unsuccessful.

Falco provided a solution by adding a script to Settings > Customize > Common > </head> to display the Topic ID after the post-meta-data. The script uses the api.decorateWidget method to add a div with the Topic ID to the post-meta-data.

nstoecki42 confirmed that this solution worked for them, and also noted that additional CSS stylesheets would be needed.

Subsequent posts from huynhthai824 and others discussed how to display the Topic ID in different locations, such as below the topic title or below the user name. fzngagan suggested trying Falco’s original solution.

Additionally, huynhthai824 asked about displaying the count of views for a topic in the post, and later asked about adding a button to move a message out of a topic.

I tried to display the Topic ID in the initial Post of all topics of a specific category but failed. I could not find a way by configuring Discourse and also a plugin - similar to Discourse BBCODE - failed to work.

Could you please give me a clear hint on how to realize to display the Topic ID in the initial Post metadata of each topic of a specific category?

I need this to continue the customer expectations of the old system as well some related functions and behavior.

Thanks a lot!

The topic_id is at the end of the URL.

Can you say more about what expectations you are tryingto may and what features you need?

As I mentioned in my Post I try to write a plugin, probably the Development category is not the proper place due I don’t want this in Discourse itself. Can you point me to some kind of solution how to display additional (existing) meta data in the initial Post Header?

I know that the URL contains the TopicID as last “Tuple” and there is also a canonical link in the html header that does. I need to display the TopicID on the initial Post. We often speak about “Topic#34074” or something and want to stay with that habit, which our customers and partners are used to.
So I tried to extract the ID (successfully) and past it into the ‘div.topic-meta-data’, which failed.

Add this to Settings > Customize > Common > </head>:

<script type="text/discourse-plugin" version="0.5">
  api.decorateWidget('post-meta-data:after', dec => {
    if (dec.attrs.post_number === 1) {
      const topic = dec.getModel().get('topic');
      return dec.rawHtml(`<div class="post-info topic-id">Topic: ${topic.get('id')}</div>`);
    }
  });
</script>

And you get:

And you just need to add some CSS.

of course, stylesheets are needed! :sunglasses:

exactly what I’m looking for - thanks a lot!!! :hugs:

안녕하세요, 주제 ID는 게시 메타 데이터 뒤에 표시됩니다.
제목 뒤에 주제를 표시하고 싶은데, 어떻게 해야 하나요?
정말 감사합니다!

component-name:after 대신 widget-name:after를 사용하면 됩니다. 아니면 원하는 위치에 플러그인 아웃렛이 있다면 그걸 사용해도 됩니다.

효과가 없어요 :frowning:

<script type="text/discourse-plugin" version="0.5">
  api.decorateWidget('component-name:after', dec => {
    if (dec.attrs.post_number === 1) {
      const topic = dec.getModel().get('topic');
      return dec.rawHtml(`<div class="post-info topic-id">Topic: ${topic.get('id')}</div>`);
    }
  });
</script>

정말 component-name widget-name을 컴포넌트의 실제 이름 대신 입력한 건가요?

토픽 ID를 사용자 이름 아래에 표시하고 싶은데, 어떤 widget-name으로 코드를 교체해야 할까요? :slight_smile:
감사합니다!

안녕하세요, 누가 저를 도와줄 수 있을까요? :frowning:

위 게시물에서 팔코가 제안한 방법을 시도해 보셨나요?

안녕하세요, 게시물에서 조회수(Count Views Topic)를 어떻게 표시할 수 있나요?

안녕하세요, ‘Message move out topic’ 버튼을 표시하는 방법에 대해 도움을 주실 분이 있을까요?

js.user.private_message

예시: