The forum topics loop can be used to output a list of forum topics.
Standard Loop Standard Loop
[sourcecode language=”php”]
<?php if ( bp_has_forum_topics() ) : ?>
<div class="pagination">
<div id="post-count" class="pag-count">
<?php bp_forum_pagination_count() ?>
</div>
<div class="pagination-links" id="topic-pag">
<?php bp_forum_pagination() ?>
</div>
</div>
<table class="forum">
<tr>
<th id="th-title"><?php _e( ‘Topic Title’, ‘buddypress’ ) ?></th>
<th id="th-poster"><?php _e( ‘Latest Poster’, ‘buddypress’ ) ?></th>
<?php if ( !bp_is_group_forum() ) : ?>
<th id="th-group"><?php _e( ‘Posted In Group’, ‘buddypress’ ) ?></th>
<?php endif; ?>
<th id="th-postcount"><?php _e( ‘Posts’, ‘buddypress’ ) ?></th>
<th id="th-freshness"><?php _e( ‘Freshness’, ‘buddypress’ ) ?></th>
</tr>
<?php while ( bp_forum_topics() ) : bp_the_forum_topic(); ?>
<tr class="<?php bp_the_topic_css_class() ?>">
<td class="td-title">
<a class="topic-title" href="<?php bp_the_topic_permalink() ?>" title="<?php bp_the_topic_title() ?> – <?php _e( ‘Permalink’, ‘buddypress’ ) ?>">
<?php bp_the_topic_title() ?>
</a>
</td>
<td class="td-poster">
<a href="<?php bp_the_topic_permalink() ?>"><?php bp_the_topic_last_poster_avatar( ‘type=thumb&width=20&height=20’ ) ?></a>
<div class="poster-name"><?php bp_the_topic_last_poster_name() ?></div>
</td>
<?php if ( !bp_is_group_forum() ) : ?>
<td class="td-group">
<a href="<?php bp_the_topic_object_permalink() ?>"><?php bp_the_topic_object_avatar( ‘type=thumb&width=20&height=20’ ) ?></a>
<div class="object-name"><a href="<?php bp_the_topic_object_permalink() ?>" title="<?php bp_the_topic_object_name() ?>"><?php bp_the_topic_object_name() ?></a></div>
</td>
<?php endif; ?>
<td class="td-postcount">
<?php bp_the_topic_total_posts() ?>
</td>
<td class="td-freshness">
<?php bp_the_topic_time_since_last_post() ?>
</td>
</tr>
<?php endwhile; ?>
</table>
<?php else: ?>
<div id="message" class="info">
<p><?php _e( ‘Sorry, there were no forum topics found.’, ‘buddypress’ ) ?></p>
</div>
<?php endif;?>
[/sourcecode]
Accepted Parameters Accepted Parameters
The bp_has_forum_topics()
function will accept a number of parameters that will manipulate the data being returned.
-
type optional
List forum topics by type.
- Accepted arguments:
newest
,popular
,unreplied
,tags
(if type equals “tags”, define the “search_terms” argument and list the tag you wish to filter by) - Default value:
newest
- Accepted arguments:
-
forum_id optional
Return only forum topics from a specific group forum.
- Default value:
false
- Default value:
-
user_id optional
Return only forum topics that this user has started.
- Default value:
false
- Default value:
-
per_page optional
Number of forum topics to display in the loop.
- Default value:
20
- Default value:
-
page optional
The page to display.
- Default value:
1
- Default value:
-
max optional
The total number of forum topics to return.
- Default value:
false
(no limit)
- Default value:
-
no_stickies optional
Return “false” if you do not want stickies listed at the top of the forum loop.
- Default value:
all
- Default value:
-
search_terms optional
Return only groups that match these search terms. When used in conjuction with “type=tags”, can use search_terms to define the tag name.
- Default value:
false
- Default value:
Examples Examples
Modifying the forum loop to list forum topics by most popular:
[sourcecode language=”php”]
<?php if ( bp_has_forum_topics( ‘type=popular’) ) : ?>
[/sourcecode]