ExpressionEngine® 3 User Guide

Legacy Documentation

You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.

Displaying Recent Forum Topics

While the Discussion Forum module is fairly self-contained, it is possible to display a simple list of “recent forum topics” in your standard Templates. You could use this to list recent threads in a sidebar on your site’s main page, for instance. An example:

Note

This tag is for use in any of your ExpressionEngine templates that are accessible via the TEMPLATES page in the control panel. It is not available for use in your forum templates. If you would like to show recent topics in your forum templates please use the {include:recent_posts} tag, which corresponds to the Archive Template: “Recent Post Table”.

<table>
        <tr>
                <td>Title</td>
                <td>Author</td>
                <td>Posted On</td>
                <td>Posts</td>
                <td>Views</td>
                <td>Last Post Info</td>
        </tr>

        {exp:forum:topic_titles orderby="post_date" sort="desc" limit="10"}
                <tr>
                        <td><a href="{thread_path='forums/viewthread'}">{title}</a></td>
                        <td><a href="{profile_path='forums/member'}">{author}</a></td>
                        <td>{topic_date format="%m/%d/%Y %h:%i %a"}</td>
                        <td>{post_total}</td>
                        <td>{views}</td>
                        <td>On: {last_post_date format="%m/%d/%Y %h:%i %a"}<br />
                        By: <a href="{last_author_profile_path='forums/member'}">{last_author}</a></td>
                </tr>
        {/exp:forum:topic_titles}
</table>

Parameters

boards=

boards="2"

Allows you to specify which boards to pull topics from by Board ID number. Board ID 1 will be used if no value is specified.

As with many other parameters that use ID specification, you can stack boards to get topics from any number of boards:

boards="2|3|4"

Or use “not” to exclude boards:

boards="not 1|4"

forums=

forums="3"

Allows you to specify which forums to pull topics from by Forum ID number. If no value is specified, the Topic Titles tag will pull from all forums in the specified boards.

As with many other parameters that use ID specification, you can stack forums to get topics from specific forums only:

forums="3|14|16"

Or use “not” to exclude forums:

forums="not 9|12"

limit=

limit="30"

Allows you to limit the number of topics displayed. The limit will default to 10 topics if a value is not specified.

orderby=

orderby="post_date"

The “order” parameter sets the display order of the forum topics. Setting options for this parameter include:

  • orderby=”post_date”
  • orderby=”recent_post”
  • orderby=”title”

sort=

sort="asc" ``sort="desc"``

The sort order can be “asc” (ascending order or “oldest item first” for dates) or “desc” (descending order or “newest item first” for dates). If you do not use a sort order the default is desc.

Variables

author

{author}

The screen name of the thread author.

auto_thread_path

{auto_thread_path}

This variable is replaced by a path built with the URL set in the “Forum URL” general preference setting for the board that the topic belongs to. For example, this:

<a href="{auto_thread_path}">{title}</a>

Would be rendered like this:

<a href="http://example.com/index.php/forums/viewthread/11245/">My forum topic</a>

board_label

{board_label}

The name of the board the topic belongs to, taken from the “Forum Board Label” general preference setting.

board_name

{board_name}

The short name of the board the topic belongs to, taken from the “Forum Board Short Name” general preference setting.

body

{body}

The contents of the topic.

Note

This variable will use the formatting preferences of the forum that the topic belongs to.

forum_name

{forum_name}

The Forum Name of the specific forum that the topic belongs to.

forum_url

{forum_url}

This variable is replaced with the URL set in the “Forum URL” general preference setting for the board that the topic belongs to.

last_author

{last_author}

The screen name of the most recent user to leave a reply in the thread. If there are no replies then the last author will be the author of the thread itself.

last_author_profile_path

{last_author_profile_path='forums/member'}

The URL to the member profile for the last user to leave a reply in the thread. If there are no replies then it will be for the author of the thread itself. For example, this:

<a href="{last_author_profile_path='forums/member'}">{last_author}</a>

Would be rendered like this:

<a href="http://example.com/index.php/forums/member/147/">Fred Smith</a>

last_post_date

{last_post_date format="%m/%d/%Y %h:%i %a"}

The date on which the last (most recent) post in the thread was made. As with other date variables, these require the “format” parameter in order to define how the date should be displayed. See the date variable formatting page for more information.

last_post_id

{last_post_id}

The id of the last reply made to the thread. Will hold a value of 0 if no replies have been made. Can be used to build links to the last reply, e.g.:

<a href="{forum_url}viewreply/{last_post_id}/">View latest reply</a>

last_post_relative_date

{last_post_relative_date}

The date on which the last (most recent) post in the thread was made, displayed relative to the current time. For instance, if you used this:

Posted {last_post_relative_date} ago

It might be displayed as:

Posted 1 hour and 23 minutes ago

last_reply

{last_reply}

If available, the contents of the most recent reply to the thread.

Note

This variable will use the formatting preferences of the forum that the topic belongs to.

post_total

{post_total}

The total number of posts in the thread.

profile_path

{profile_path='forums/member'}

The URL to the member profile of the thread author. For example, this:

<a href="{profile_path='forums/member'}">{author}</a>

Would be rendered like this:

<a href="http://example.com/index.php/forums/member/147/">Fred Smith</a>

thread_path

{thread_path='forums/viewthread'}

The URL to the thread at the specified Template. For example, this:

<a href="{thread_path='forums/viewthread'}">{title}</a>

Would be rendered like this:

<a href="http://example.com/index.php/forums/viewthread/42/">My Forum Thread</a>

title

{title}

The title for the thread.

topic_date

{topic_date format="%m/%d/%Y %h:%i %a"}

The date on which the thread was posted. As with other date variables, these require the “format” parameter in order to define how the date should be displayed. See the date variable formatting page for more information.

topic_relative_date

{topic_relative_date}

The date on which the thread was posted, displayed relative to the current time. For instance, if you used this:

Posted {topic_relative_date} ago

It might be displayed as:

Posted 1 hour and 23 minutes ago

views

{views}

The number of times the thread has been viewed.