Recent Topics Widget - Jump to last post
-
Hi,
I'm stuck on editing the widgets/recenttopics.tpl so that the link of the topic title brings a user directly to the last post, currently one comes to the first post.
This is the implementation of widgets/recenttopics, bringing you to the first post:
<a href="{relative_path}/topic/{topics.slug}">{topics.title}</a>
This is the implementation in categories.tpl that takes a user to the last post (Slick theme btw):
{{{ each categories.posts }}} .... <a class="permalink" href="{config.relative_path}/topic/{../topic.slug}<!-- IF ../index -->/{../index}<!-- ENDIF ../index -->">
Can someone explain or the send me an link how the hierachy of the templating system? I looked at https://docs.nodebb.org/development/themes/templates/#templating-logic but I don't understand how to deal with it.
I guess I need something like
<a href="{relative_path}/topic/{topic.slug}<!-- IF topics.posts.index -->/{topics.posts.index}<!-- ENDIF topics.posts.index -->">{topics.title}</a>
This doesn't work and I obviously don't understand how to 'navigate' between What is before if I do ../topics for example? How can I learn this?
Thanks
edit: I thought these are called hooks, but I was wrong
-
What is your setting in the ACP for teasers?
And how many posts does the topic have? I think your code should work if the setting is set toLast
. If the teaser object is populated it should have theindex
andpid
properties then you can use those to make a link to the post in two ways.<a href="{relative_path}/topic/{topics.slug}/{topics.teaser.index}">{topics.title}</a>
or
<a href="{relative_path}/post/{topics.teaser.pid}">{topics.title}</a>
-
It is set to
Last
. The post count is different for every thread, there are 5 topics showing up in my widget but with my snippet none of them is linked to the latest post. I'm not sure if the teaser object is popluated. I will try your other snippet now. Thanks!Btw. is there a way to exclude categories from the widget? For example we have an admin category, private and not visible for users. If we have 4 recent topics related to that category, users will only see 1 recent topic in the widget (admins see 5 of course).
-
@baris said in Recent Topics Widget - Jump to last post:
<a href="{relative_path}/post/{topics.teaser.pid}">{topics.title}</a>
Nope, still not working. This is how my code looks right now:
<div class="recent-replies"> <ul id="recent_topics" data-numtopics="{numTopics}"> <!-- BEGIN topics --> <li class="clearfix widget-topics"> <a href="<!-- IF topics.teaser.user.userslug -->{relative_path}/user/{topics.teaser.user.userslug}<!-- ELSE -->#<!-- ENDIF topics.teaser.user.userslug -->"> <!-- IF topics.teaser.user.picture --> <img title="{topics.teaser.user.username}" class="avatar avatar-sm not-responsive" src="{topics.teaser.user.picture}" /> <!-- ELSE --> <div class="avatar avatar-sm not-responsive" style="background-color: {topics.teaser.user.icon:bgColor};">{topics.teaser.user.icon:text}</div> <!-- ENDIF topics.teaser.user.picture --> </a> <p> <a href="{relative_path}/post/{topics.teaser.pid}">{topics.title}</a> </p> <span class="pull-right post-preview-footer"> <span class="timeago" title="{topics.lastposttimeISO}"></span> </span> </li> <!-- END topics --> </ul> </div>
I did some rebuilds & reboots of course. Could it be cache related?
-
Do you see the changes you make to the template? When you add some html does it show up on the widget? When you make changes to that template you need to stop nodebb and rebuild with
./nodebb build
. I am assuming you are making the changes innode_modules/nodebb-widget-essentials
directory. -
I'm doing the changes with nodebb-plugin-customize. And I edited another template right now and no - the html is not in the DOM but shows up when I open the template with the plugin. Do you think it's better to do the changes like you assumed?
-
Thank you @baris it's working when I edit the files without the plugin. Not sure what's the problem.
Any suggestion to this one? "Btw. is there a way to exclude categories from the widget? For example we have an admin category, private and not visible for users. If we have 4 recent topics related to that category, users will only see 1 recent topic in the widget (admins see 5 of course)."
Or should I open a new topic?