Support Forum

Want post loop within topic on Forum View

KA Kathryn
Kathryn
Member

Is there a way I can add a post loop within my topic loop on the spForumView? The minute I add ” if (sp_has_posts()): ” within my topic loop, it seems as if there is an error as the page does not display anything below that including static text.

I am using the iForum theme as a base and have a requirement that when the topics are displayed for a forum – all the full posts (with content) below those topics are displayed so the end-user does not have to click on different pages to see the posts for different topics

5 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

How bizarre and how intriguing. What happens when there are hundreds of topics?

OK – I have never tried this but hey – let’s see if we can work something out.

Have you used sp_this_topic($id) to populate the data object? You would need to do that before starting the posts loop and would need to pass in the topic ID.

KA Kathryn
Kathryn
Member

I did not think I needed to do sp_this_topic when I was within the following topic loop:

                            if (sp_has_topics()) : while (sp_loop_topics()) : sp_the_topic();

But if I do indeed need to do sp_this_topic – where do I get the topic ID from? I can’t find any reference in the API for that (and $id as you explicitly put it does not work as the following if statement returns false

if(sp_this_topic($id))

And yes this is a rather bizarre request (not one I would prefer but the end user wants to be able to view everything with out any extra clicks) but the number of posts will be controlled and very low so hopefully it will work.

 

YS Yellow Swordfish
Yellow Swordfish
Member

Sorry about the incomplete Codex. We are populating it as fast as Brandon can write!

If you look at the three main views (not using iForum theme but say, default theme) then each one populates a data object. The first populates the groups and the forum rows. the second the selected forum and topic rows and the third the selected topic and post rows. So the forum data object ($spForumView) only has that forum record and related topic data (to fill the current page). That also generates the $spThisTopic data object which points to the current topic being displayed.

Calling sp_this_topic() will populate the $spTopicView data object and it’s collection – $spThisTopic. This has to be done before the loop is started. To pass the topic ID just use $spThisTopic->topic_id.

If you go to the forum admin > Toolbox > Data Inspector you can actually display all of these data objects to the screen when you display the relevant page which is very useful to see what data is in each collection object.

But I still don’t know for sure what will happen when you try this. I am actually both horrified and fascinated smile

KA Kathryn
Kathryn
Member

Thanks – that gave me the missing pieces and I now have it working and it is fine with the limited numbers of posts that we will have.

Thanks for all the help!

 

MP Mr Papa
Mr Papa
Member

good news!  its really just a lot like the wp loop… only more of them… ;)

would love to see the site when you finish with it!