Please or Register to create posts and topics.

Search result as post list

Hello,

 

this is possible that forum search result displays a post list instead of a topic list (maybe like the page “history post of a profile) ?

 

thank you

Hello @alemarc

Currently this is not possible. I will evaluate if I can improve this in a future update.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

@asgaros Ok

Here some hardcoded changes I maked to change search results, maybe useful for anybody.

I add 2 new functions into (show_custom_search_results + get_custom_search_results) and call show_custom_search_results() into forum.php in case of ‘search’ (function forum(), line 724).

forum-search.php :

public function show_custom_search_results() {
  echo '<div id="search-post-layer">';
    $posts = $this->get_custom_search_results();
    if (empty($posts)) {
      $notice = __('No results found for:', 'asgaros-forum').'&nbsp;<b>'.$this->search_keywords_for_output.'</b>';
      $this->asgarosforum->render_notice($notice);
    } else {
      $pagination = $this->asgarosforum->pagination->renderPagination('search');

      if ($pagination) {
        echo '<div class="pages-and-menu">'.$pagination.'</div>';
      }

      foreach ($posts as $post) {
        echo '<div class="search-post-element">';
          echo '<div class="search-post-author">';
            // Show avatar if activated.
            if ($this->asgarosforum->options['enable_avatars']) {
              $avatar_size = apply_filters('asgarosforum_filter_avatar_size', 40);
              echo get_avatar($post->author_id, $avatar_size, '', '', array('force_display' => true));
            }

            echo '<div class="post-author-block-name">';
              // Show username.
              $username = apply_filters('asgarosforum_filter_post_username', $this->asgarosforum->getUsername($post->author_id), $post->author_id);
              echo '<span class="post-username">'.$username.'</span>';
            echo '</div>';
          echo '</div>';

          $link = $this->asgarosforum->rewrite->get_post_link($post->id, $post->parent_id);
          $text = $this->asgarosforum->strip_tags_content($post->text, '<blockquote>', TRUE);
          $text = esc_html(stripslashes(strip_tags($text)));
          $text = $this->asgarosforum->cut_string($text, 200);
          $text = str_ireplace($this->search_keywords_for_output, '<strong>'.$this->search_keywords_for_output.'</strong>', $text);
          echo '<a class="search-post-text" href="'.$link.'"><div>'.$text.'</div></a>';


          $topic_link = $this->asgarosforum->rewrite->get_link('topic', $post->parent_id);
          $topic_name = esc_html(stripslashes($post->name));
          $topic_time = $this->asgarosforum->format_date($post->date);

          echo '<div class="search-post-meta">';
            echo '<span class="search-post-topic">';
              echo _e('Subject:', 'asgaros-forum').' <a href="'.$topic_link.'">'.$topic_name.'</a>';
            echo '</span>';
            echo '<span class="search-post-time">'.$topic_time.'</span>';
          echo '</div>';
        echo '</div>';
      }

      if ($pagination) {
        echo '<div class="pages-and-menu">'.$pagination.'</div>';
      }
    }
  echo '</div>';

}

public function get_custom_search_results() {

  if (!empty($this->search_keywords_for_query)) {
    // search key words no empty

    $categories = $this->asgarosforum->content->get_categories();
    if (empty($categories)) {
      // Cancel if the user cant access any categories.
      return false;
    }

    $categoriesFilter = array();
    foreach ($categories as $category) {
      $categoriesFilter[] = $category->term_id;
    }
    $accessible_categories = implode(',', $categoriesFilter);

    $elements_maximum = 50;
    $elements_start = $this->asgarosforum->current_page * $elements_maximum;
    $query_limit = "LIMIT {$elements_start}, {$elements_maximum}";

    $match_text = "MATCH (text) AGAINST ('{$this->search_keywords_for_query}*' IN BOOLEAN MODE) ";
    $query_match_text = "SELECT * FROM {$this->asgarosforum->tables->posts} WHERE {$match_text} GROUP BY parent_id ";

    $query = "SELECT p.id, p.author_id, p.text, p.date, p.parent_id, t.name ".
        " FROM ".
          "( {$query_match_text} ) AS p, ".
          "{$this->asgarosforum->tables->topics} AS t ".
        " WHERE p.parent_id = t.id ".
        " AND EXISTS ".
          "(SELECT f.id ".
            "FROM {$this->asgarosforum->tables->forums} AS f ".
            "WHERE f.id = t.parent_id ".
            "AND f.parent_id IN ( {$accessible_categories} )
          ) ".
        " AND t.approved = 1 ".
        " ORDER BY p.id DESC {$query_limit};";
    
    $results = $this->asgarosforum->db->get_results($query);

    if (!empty($results)) {
      return $results;
    }
  }

  return false;
}

Here CSS custom for display :

.search-post-element {
  display: flex;
  align-items: stretch;
  padding: 0;
  background: none;
  background: radial-gradient(ellipse at center,#ffffff 0%,#fff6ee85 100%);
  border: 1px solid #eee;
  margin-bottom: 20px;
  border-radius: 10px !important;
}
.search-post-author {
  text-align: center;
  min-width: 120px;
  width: unset;
  background: #ffe0a53b;
  background: -moz-radial-gradient(center, ellipse cover, #fff 0%, #ffe0a53b 100%);
  background: -webkit-radial-gradient(center, ellipse cover, #ffffff 0%,#ffe0a53b 100%);
  background: radial-gradient(ellipse at center, #fff 0%,#ffe0a53b 100%);
  box-sizing: border-box;
  border-right: 1px solid #eee;
  padding: 10px 0;
}
.search-post-text {
  display: inline-block;
  width: calc(100% - 370px);
  text-overflow: ellipsis;
  overflow: hidden;
  padding: 10px;
  padding-left: 30px;
}
a.search-post-text:hover {
  color: black !important;
  text-decoration: none;
  background: rgb(255, 248, 237);
}
.search-post-meta {
  display: flex;
  flex-direction: column;
  text-align: center;
  min-height: 100% !important;
  justify-content: center;
  width: 220px;
  white-space: nowrap;
  min-width: 220px;
  max-width: 220px;
  font-size: small;
  align-items: stretch;
  border-left: 1px solid #eee;
  background: #ffe0a53b;
  background: -moz-radial-gradient(center, ellipse cover, #fff 0%, #ffe0a53b 100%);
  background: -webkit-radial-gradient(center, ellipse cover, #ffffff 0%,#ffe0a53b 100%);
  background: radial-gradient(ellipse at center, #fff 0%,#ffe0a53b 100%);
}
.search-post-time {
  font-style: italic;
  color: #777;
}
#af-wrapper .search-post-topic a {
  background: #91288e;
  padding: 2px 10px;
  border-radius: 10px;
  color: white !important;
}

 

And here a result sample :

 

 

 

Asgaros, qualmy91 and Carewen have reacted to this post.
Asgarosqualmy91Carewen

Hi @alemarc

Nice custom implementation! Maybe I can add something similar in the core of the plugin.

user1 has reacted to this post.
user1
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hi

It would be very nice to, update this post, because it does not work on current Asgaros version.

Best and kind regards