Add an "Unanswered" filter to the "New posts" widget

Steffen

Well-known member
I want to show an "Unanswered threads" widget at the bottom of our forum homepage. Building a completely new widget seems to be overkill because a simple addition to the "New posts" widget is all that's needed. Maybe this could ship as part of XenForo?

Diff:
--- a/src/XF/Widget/NewPosts.php
+++ b/src/XF/Widget/NewPosts.php
@@ -61,6 +61,13 @@ class NewPosts extends AbstractWidget
                 $title = \XF::phrase('widget.latest_watched');
                 $link = $router->buildLink('whats-new/posts', null, ['watched' => 1]);
                 break;
+
+            case 'unanswered':
+                $threadFinder = $threadRepo->findThreadsWithNoReplies();
+                $threadFinder->where('discussion_state', 'visible');
+                $title = \XF::phrase('widget.unanswered_threads');
+                $link = $router->buildLink('find-threads/unanswered');
+                break;
         }
 
         $threadFinder


Except for some new phrases, the only other required change is that the widget_def_options_new_posts template needs the additional option:
HTML:
    <xf:option value="unanswered"
        label="{{ phrase('new_posts_unanswered') }}"
        hint="{{ phrase('new_posts_filter_unanswered_explain') }}" />
 
Upvote 8
Back
Top Bottom