CMS Widget to post most recent topic via forum post

By Acruze , Mar 15, 2026
  • Acruze @Acruze
    Mar 15, 2026

    Hello everyone, absolutely loving the forumify and MILHQ systems. I have a suggestion; would it be possible to create a forum widget that would post the most recent topic from a specified forum? An example of this use would be if I had unit updates I could post them to a specific forum and it would be automatically posted to the main page where I would have such a widget, we could use this for promotions, awards, operations updates, etc.


  • jannes @jannes
    Mar 15, 2026

    Hi Cruze,

    Good suggestion! We actually use such a widget on our own homepage as well to show developer news and releases. We can add some forum related widgets to our 1.1 release.

    If you're not afraid to get your hands dirty with some code, you could a "Twig" widget with the following code:

    {% set forumSlug = 'my-cool-forum' %}
    {% set topicCount = 3 %}
    
    {% set forum = repository('Forum').findOneBy({ slug: forumSlug }) %}
    {% set topics = repository('Topic').findBy({ forum: forum.id }, { createdAt: 'desc' }, topicCount) %}
    <div class="text-left">
        <div class="box flex flex-col forum-topics">
            {% for topic in topics %}
                <a class="flex flex-col items-start justify-center text-left relative forum-topic flex-wrap"
                   href="{{ path('forumify_forum_topic', { slug: topic.slug }) }}"
                   aria-label="{{ topic.title }}">
                    <p>{{ topic.title }}</p>
                    <p class="text-smallest text-secondary date">{{ topic.createdAt|format_date }}</p>
                </a>
                {% if not loop.last %}
                    <hr>
                {% endif %}
            {% endfor %}
        </div>
        <a href="/forum/{{ forumSlug }}" class="btn-link read-more mt-2">
            <i class="ph ph-caret-right"></i> Read More
        </a>
    </div>
    

    Just change the variables at the top, replace the variable forumSlug with the forum's slug (found in the url, for example: example.org/forum/this-part-is-the-slug), and the topicCount with how many topics you'd like to pull from that forum.

    If you also want to show the topic's content, it is available in topic.firstComment.content, just need to wrap it with some rich text, for example:

    <div class="rich-text">{{ topic.firstComment?.content ?? '' }}</div>
    

    You can paste that before the `{% if not loop.last %}` part for example.

    Thanks for the suggestion.


  • Acruze @Acruze
    Mar 15, 2026

    Yes, I have been using twig and it has helped me a lot, but I am very new with it and have to research a lot, lol.