Forums

The great place to discuss topics with other users

Add blogs to hashtags

'
Join the Conversation Post Reply
Jane Marcia
Admin
Joined: 2025-05-17 02:14:16
2025-06-01 09:09:02

This is core edit because of 2 reasons

1- you may not be using my Plugin System

2- I am doing this on my other site and want to finish fast for now...

Hashtags for blogs

First open class-user.php and look for 

public function get_trending_hashtags($user_id = null)

Now replace the entire fuction block with 

public function get_trending_hashtags($user_id = null)
{
  global $system, $db;
  $hashtags = [];

  // POST hashtags
  $where_query_posts = "";
  if ($user_id) {
    $user_id_secure = secure($user_id, 'int');
    $where_query_posts = " AND hashtags_posts.post_id IN (SELECT post_id FROM posts WHERE posts.user_id = {$user_id_secure} AND posts.user_type = 'user')";
  }

  $query_posts = sprintf(
    "SELECT hashtags.hashtag, COUNT(hashtags_posts.id) AS frequency
     FROM hashtags
     INNER JOIN hashtags_posts ON hashtags.hashtag_id = hashtags_posts.hashtag_id
     WHERE hashtags_posts.created_at > DATE_SUB(CURDATE(), INTERVAL 1 %s)
     %s
     GROUP BY hashtags_posts.hashtag_id",
    secure($system['trending_hashtags_interval'], "", false),
    $where_query_posts
  );

  $results = $db->query($query_posts);

  if ($results && $results->num_rows > 0) {
    while ($hashtag = $results->fetch_assoc()) {
      $hashtag['hashtag'] = html_entity_decode($hashtag['hashtag'], ENT_QUOTES);
      $hashtags[$hashtag['hashtag']] = $hashtag['frequency'];
    }
  }

  // BLOG tags (comma-separated)
  $query_blogs = "
  SELECT posts_articles.tags 
  FROM posts_articles 
  INNER JOIN posts ON posts.post_id = posts_articles.post_id 
  WHERE posts.time > DATE_SUB(CURDATE(), INTERVAL 1 " . secure($system['trending_hashtags_interval'], "", false) . ")
";

if ($user_id) {
  $query_blogs .= " AND posts.user_id = " . secure($user_id, 'int') . " AND posts.user_type = 'user'";
}


  $blog_tags_result = $db->query($query_blogs);

  if ($blog_tags_result && $blog_tags_result->num_rows > 0) {
    while ($row = $blog_tags_result->fetch_assoc()) {
      $tags = array_map('trim', explode(',', $row['tags']));
      foreach ($tags as $tag) {
        if (!isset($hashtags[$tag])) {
          $hashtags[$tag] = 1;
        } else {
          $hashtags[$tag]++;
        }
      }
    }
  }

  // Convert associative array back to list sorted by frequency
  arsort($hashtags);
  $hashtags = array_slice($hashtags, 0, (int)$system['trending_hashtags_limit'], true);

  // Final output format
  $final = [];
  foreach ($hashtags as $tag => $count) {
    $final[] = [
      'hashtag' => html_entity_decode($tag, ENT_QUOTES),
      'frequency' => $count
    ];
  }

  return $final;
}

Now open _trending_widget.tpl

Look for 

<a class="trending-item" href="{$system['system_url']}/search/hashtag/{$hashtag['hashtag']}">

and replace with 

<a class="trending-item" href="{$system['system_url']}/search/hashtag/{$hashtag['hashtag']|replace:' ':'_'}">

That is all, I do not have it installed here yet, added to my main website and it works fine.