Info
- 7 posts
- 2 voices
- Started 2 years ago by massbase
- Latest reply from massbase
- This topic is resolved
How do I loop through EACH forum?
-
- Posted 2 years ago #
how do i loop through each forum to echo the latest topics for each one seperatly... rather than blast out the entire topics of every forum at once.
-
- Posted 2 years ago #
I didn't find how to loop each category if there is such as thing, but I found this solution, its WORKS fine...
<?php if ( $topics ) : foreach ( $topics as $topic) : ?> <?php $doof = $topic->forum_id; if ($doof=="1") { ?> <p><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a><?php topic_page_links(); ?></p> <?php } ?> <?php endforeach; endif; ?> -
- Posted 2 years ago #
Still a problem, becuase the above solution spits out all the topics and not only 3 as Required..
can anyone help, on how to do a FOR loop for this, i dont get how the array $topics works?
please help.
-
- Posted 2 years ago #
- Initialize a variable as zero.
- Increment it every time you display a topic (every iteration) if the value of variable is less than 3.
- As soon as it grows >3, breaks out of the loop.
-
- Posted 2 years ago #
if you know how to do this please, show me, <?php topic_title(); ?> seems as though it can only be used in a that foreach loop, i cant do a for loop and add ing <?php topic_title(); ?> inside of it.
-
- Posted 2 years ago #
Although I havn't tested it but it should work:
<ul> <?php $count=0; if ( $topics ) { foreach ( $topics as $topic) { $doof = $topic->forum_id; if ($doof=="1") { if($count<3) $count++; else break; ?> <li><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a> | <?php topic_page_links(); ?></li> <?php } } } ?> </ul> -
- Posted 2 years ago #
Man you rock!
thanks a bunch for this.
-
You must log in to post.