The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A button to show only the topic starter's posts

3 posters

Go down

staff posts - A button to show only the topic starter's posts Empty A button to show only the topic starter's posts

Post by nina81331 September 6th 2020, 7:22 pm

Hello. This is my forum: click it

I need a button in a topic to click to show only the topic starter's posts.
And this is the explanatory diagram by @Winging.
staff posts - A button to show only the topic starter's posts Iau10


So I have tried like this:

Code:

$(function(){
    $("#author_only").click(function(e){
          e.preventDefault();
          var id=$(".postrow").first().find(".poster_name").find("a").text();
  id='{TOPIC_POSTER}';
          if($(this).hasClass("only")){
                $(this).removeClass("only").text("只看作者(It means only see the topic starter's posts)");
         
          $(".postrow").show();
         
          }
          else{
                $(this).addClass("only").text("顯示其他評論(It means see all posts)");
         
                $(".postrow").map(function(){
                      if($(this).find(".poster_name").find("a").text()!=id){
                      $(this).hide();
                      }
                });
          }

But this code can be worked only in the first page.
I can not find the code which can catch the topic starter. And that is the key to create it.

I hope to get your help here.
Thank you for reading!
nina81331
nina81331
New Member

Posts : 6
Reputation : 1
Language : Chinese

https://takarazukafiction.forumotion.asia/

Back to top Go down

staff posts - A button to show only the topic starter's posts Empty Re: A button to show only the topic starter's posts

Post by tikky September 7th 2020, 2:32 pm

Hello @nina81331,

Welcome to Forumotion Support Forum! But your code is working? Because i see a lot of errors Shut

But this code can be worked only in the first page.
I can not find the code which can catch the topic starter. And that is the key to create it.
Go to Adminstration Panel > General > Messages and emails > Configuration in the option "Always show the first post in the topics" mark as "Yes"!
tikky
tikky
Forumember

Posts : 898
Reputation : 157
Language : 🇵🇹

https://www.forumotion.com/create-forum/modernbb

Back to top Go down

staff posts - A button to show only the topic starter's posts Empty Re: A button to show only the topic starter's posts

Post by Wecoc September 22nd 2020, 5:27 pm

Hi. You can get the topic starter using jQuery to get the first page and read the posts from there.

Code:
function current_topic(){
  return window.location.href.replace(/\/t(\d*)p(\d*)-/, "/t$1-").replace(/\#(\d*)$/, "");
}
$.get(current_topic(), function(d){
  var post = $(".post", d)[0];
  console.log(post); // First post
});

But I wouldn't do it like that, because even with that you are only filtering the posts on the current page. In some cases there could be no posts by the topic starter on that page so the result would be empty, which is a bit weird.

What I would do is get the posts of all the pages of the topic, so when you are "filtering" you are not restrained on topic pages at all. With that you can also easily make a filter by another of the active users on that topic.

The second widget on this topic could help you a bit with that: Widgets for categories and posts
Hope it helps.
Wecoc
Wecoc
Forumember

Male Posts : 144
Reputation : 111
Language : Catalan, Spanish, English

TonnyKamper likes this post

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum