Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: rgpedro - toukokuu 21, 2014, 05:59:49 AP

Otsikko: help: show number of replies of a topic in a page outside smf
Kirjoitti: rgpedro - toukokuu 21, 2014, 05:59:49 AP
Dear friends,
I would like to know how can I show the number of replies of a specific topic in a page outside SMF.
What I want to do is in a specific wordpress post, show the number of replies of the topic related to the post(I manually create the topic and then I put the link on the wordpress post).
Many many thanks.
Otsikko: Re: help: show number of replies of a topic in a page outside smf
Kirjoitti: live627 - toukokuu 21, 2014, 11:55:00 AP
- Do you add the link to the body or inside a custom field?
- Are WordPress and SMF bridged?
Otsikko: Re: help: show number of replies of a topic in a page outside smf
Kirjoitti: rgpedro - toukokuu 21, 2014, 01:52:26 IP
Lainaus käyttäjältä: live627 - toukokuu 21, 2014, 11:55:00 AP
- Do you add the link to the body or inside a custom field?
- Are WordPress and SMF bridged?

First, thank you very much for your attention!
I did not bridge them, and I link the forum topic manually in the respective post, I mean, like, I creat the post in WP and in the bottom I add "discuss it here"(link to the forum) - then I would like anywhere near it, to have the reply count shown.
I can do in a custom field, or any way you think it´s best or easier.
If you think that it´s good or better to bridge them somehow, I can give it a try!
Thank you again.
Otsikko: Re: help: show number of replies of a topic in a page outside smf
Kirjoitti: margarett - toukokuu 21, 2014, 09:08:07 IP
If you can run PHP in that WP block, you can query SMF's database, table smf_topics and fetch the column "num_replies". The ID is in the topic link you put there ;)
Otsikko: Re: help: show number of replies of a topic in a page outside smf
Kirjoitti: margarett - toukokuu 22, 2014, 07:43:34 AP
(PM follow-up)
I'm sorry but I'm an absolute stranger to WP's code... What I imagine you need is something like (abstract):
* You create a post and, inside, you past a link to your forum topic.
* When someone is viewing that post you created, there should be an indication of the number of replies that topic has. In order to do this, there should be a piece of code, somewhere where WP displays the posts, that:
a) checks if, in the post body, there is the following text: http://www.yourforum.com/index.php?topic= (of course, you need to adjust it with your forum URL)
b) if yes, then fetch the topic ID --> the number after the "=" and the following "." (because you should paste something like 123455.0)
c) if yes, query SMF's database, table "smf_topics" and retrieve the column "num_replies", WHERE id_topic = the_topic_id_you_got_in_previous_point
d) if yes and the query presented some results, append some text, eg: "This topic has XX replies", where "XX" is the result of the previous query.

This is something you should take to WP support/community, probably. This pseudo-code should be enough for someone who can work WP's code...
Otsikko: Re: help: show number of replies of a topic in a page outside smf
Kirjoitti: rgpedro - toukokuu 22, 2014, 09:52:28 AP
Bruno,
A big thank you.