Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Want post loop within topic on Forum View
Avatar
Kathryn
Rookie
Free Members
sp_UserOfflineSmall Offline
Nov 28, 2012 - 12:12 pm

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

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 28, 2012 - 2:20 pm

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.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Kathryn
Rookie
Free Members
sp_UserOfflineSmall Offline
Nov 28, 2012 - 2:58 pm

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.

 

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 28, 2012 - 4:22 pm

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

andy-signature.png
YELLOW
SWORDFISH
Avatar
Kathryn
Rookie
Free Members
sp_UserOfflineSmall Offline
Nov 28, 2012 - 8:06 pm

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!

 

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 28, 2012 - 9:00 pm

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!

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 621
Members: 17368
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79627