Skip to content


bstat Search Cloud

Casey over at MaisonBisson has developed a sweet WordPress plugin called bstat. I’ve been using it since I installed WordPress as my blog. Well, one thing that is missing from the plugin that I decided I wanted was a search cloud (like a tag cloud, only for incoming searches)… I recently created a tag cloud on MasterWish so decided to use that. Here’s the function.

Special Functions

  • bstat_search_cloud

Usage:

bstat_search_cloud(post_id, maxresults, days, starting_font_size);

  • post_id is the post_id for the story, usually provided by a WP variable. A value of 0 is used for grabbing all search terms from any post
  • maxresults is the number of search terms you wish to retrieve
  • days is the number of days back to look
  • starting_font_size is the starting font size of the smallest search term

Example:


<h3>All incoming search terms for this post</h3>
<small>< ?php bstat_search_cloud(0,50); ?></small>

Posted in Blog, Random News, Technology.

Tagged with , , , , , , , .


22 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Casey says

    Good stuff. I’m marking it for inclusion in the next release.

  2. Jamie says

    Hi

    This is just what I am looking for, but how do I add it to my blog.

    Some help would be great.

    Jamie

  3. Matt says

    @Jamie

    You need to have bsuite installed first. Once that is installed and running, simply refer to the example in this blog post.

  4. Jack says

    is it add

    ‘;

    $request=”select num from (select * from (select distinct(ref) ref,count(ref) num from wp_bstat_refs WHERE ref not like ‘http%’ and ref not like ‘www%’ AND bstat_date > ‘$date’ $post_id group by ref) t1 order by num desc limit 0,$maxresults) t2 order by num asc limit 0,1″;
    if($row=$wpdb->get_results($request))
    {
    $divisor=ceil($row[0]->num/$starting_font_size);

    $request = “select * from (select * from (select distinct(ref) ref,count(ref) num from wp_bstat_refs WHERE ref not like ‘http%’ and ref not like ‘www%’ AND bstat_date > ‘$date’ $post_id group by ref) t1 order by num desc limit 0,$maxresults) t2 order by ref”;
    $rows = $wpdb->get_results($request);
    foreach($rows as $row)
    {
    $tag=array(
    ‘ref’=>$row->ref,
    ‘num’=>$row->num
    );

    $rows2 = $wpdb->get_results(“SELECT * FROM wp_bstat_refs WHERE ref=’”.$tag['ref'].”‘”);
    $tag['link']=get_permalink($rows2[0]->post_id);
    $tag['size']=10;
    $tag['size']+=(floor(($tag['num']/$divisor)/$starting_font_size)*2);
    $tag['size']=($tag['size']>30)?30:$tag['size'];
    $tag['ref']=str_replace($search,$replace,$tag['ref']);
    $text.=’‘.$tag['ref'].’  ‘.”\n”;
    }//end foreach
    $text.=”;
    echo $text;
    }//end if
    }//end bstat_search_cloud
    ?>

    to bsuite code?

  5. Jack says

    i have the error after that..

  6. robinson says

    I’ve been looking for bstat but I can’t find a valid url. including the one at MaisonBisson… is there any one who knows the valid url for downloading the bstat? if there’s a tutorial it would be very help full…. thanks..

  7. Matt says

    Bstat has gone through a name change a while back and is now known as Bsuite. You can find it here

  8. Budi S says

    Can you gi give me bstat.zip ….
    because i have download but it can’t be opened …
    thx

  9. peter says

    hi Matt, I have install latest bsuite and activate it. but I do not know how and where to add “bstat_search_cloud” and “All incoming search terms for this post
    ” . can you give me detail steps, thank very much

  10. GadgetHeat says

    Hi Matt

    I am trying to adjust your code for bsuit4 so that I can show the incoming search cloud in my posts but am having no luck. I have adjusted you syntax as below but I get the following error

    ‘WordPress database error: [Unknown column 'post_id' in 'where clause']
    select num from (select * from (select distinct(name) name,count(name) num from wp_bsuite4_hits_terms WHERE name not like ‘http%’ and name not like ‘www%’ AND post_id=1654 group by name) t1 order by num desc limit 0,50) t2 order by num asc limit 0,1′

    Can you please tell me where I am going wrong and prefferably how to fix it? My code is below:

    <?php
    function bstat_search_cloud($post_id, $maxresults, $days=365, $starting_font_size=9)
    {
    global $wpdb, $bsuit4_hits_table;
    $search=array(‘tag/’,'tags/’);
    $replace=array(”,”);

    $date = date(“Y-m-d”, mktime(0, 0, 0, date(“m”) , date(“d”) – $days, date(“Y”)));
    $post_id=($post_id)?” AND post_id=$post_id”:”;

    $text=”;

    $request=”select num from (select * from (select distinct(name) name,count(name) num from wp_bsuite4_hits_terms WHERE name not like ‘http%’ and name not like ‘www%’ $post_id group by name) t1 order by num desc limit 0,$maxresults) t2 order by num asc limit 0,1″;
    if($row=$wpdb->get_results($request))
    {
    $divisor=ceil($row[0]->num/$starting_font_size);

    $request = “select * from (select * from (select distinct(name) name,count(name) num from wp_bsuite4_hits_terms WHERE name not like ‘http%’ and name not like ‘www%’ $post_id group by name) t1 order by num desc limit 0,$maxresults) t2 order by name”;
    $rows = $wpdb->get_results($request);
    foreach($rows as $row)
    {
    $tag=array(
    ‘name’=>$row-> name,
    ‘num’=>$row->num
    );

    $rows2 = $wpdb->get_results(“SELECT * FROM wp_bsuite4_hits_terms WHERE name =’”.$tag['name'].”‘”);
    $tag['link']=get_permalink($rows2[0]->post_id);
    $tag['size']=10;
    $tag['size']+=(floor(($tag['num']/$divisor)/$starting_font_size)*2);
    $tag['size']=($tag['size']>30)?30:$tag['size'];
    $tag['name']=str_replace($search,$replace,$tag['name']);
    $text.=’‘.$tag['name'].’  ‘.”\n”;
    }//end foreach
    $text.=”;
    echo $text;
    }//end if
    }//end bstat_search_cloud
    ?>

    Thanks
    Saif

  11. GadgetHeat says

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

  12. GadgetHeat says

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Hello,

    it didn’t worked for you , you are still gettings errors.

    -DS

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

    Finnaly got this working (Yay me!) If anybody wants to know contact me via my website

  13. GadgetHeat says

    It is working fine. Look at the bottom of my individual posts. You will see incoming search terms linked to the post title.

    The only problem I have left is excluding search terms which have key characters such as ‘\’. I need to escape these then everything will be perfect.

  14. DS says

    Nice job GadgetHeat , awesome !

    It’s working fine …i was looking for posts where there wasnt’ any incoming searches…my bad.

    Anway can you help me with this..i am struggling for this for last 2 weeks and haven’t done any progress. I have got bsuite plugin activated, and created a seprate function, then added that function into functions.php..but it doesn’t work .
    Thanks !

  15. Urban says

    Nice job GadgetHeat , awesome !
    It’s working fine …i was looking for posts where there wasnt’ any incoming searches…my bad.
    Anway can you help me with this..i am struggling for this for last 2 weeks and haven’t done any progress. I have got bsuite plugin activated, and created a seprate function, then added that function into functions.php..but it doesn’t work .
    Thanks !

    Hi,

    I was trying to contact you through your form on the website, but the page didn’t work, some php error… so I contacted an email address that I found on your website. Don’t know if it works.

    Anyhow, can you help me with the solution? I’m stuck.

    And did you solve the character issues? I for example have lots of articles containing the “-” character. Is this a problem? Or do I understand this wrong? Where is that character issue coming up?

  16. Binh Nguyen says

    Thank you for this special function. I’m looking for something to do search cloud like yours.

    But there is a problem. Does this still work for the current bSuite plugin? If not… do you have any fix?

    Thanks.

  17. Gautam says

    @GadgetHeat: care to share what needs to be done.

    Anyone else got it to work ?

    Any lead would be of great help.

    /G

  18. Incoming Search Term Tagging says

    I finally got “Top incoming search terms for this post” to work:

    Folks who still are looking for it, can look at it at :

    http://www.techbuzz.in/top-incoming-search-terms-for-this-post-incoming-search-term-tagging.php

  19. Clara Lopez says

    xogc9iqasrwgxe4v

  20. Free ebook says

    need help, it return with error:
    get_results($request))
    {
    what should i do

  21. ridwanessa says

    nice plugins

Continuing the Discussion

  1.   Top incoming search terms for this post - incoming search term tagging by Gautam H N linked to this post on November 10, 2008

    [...] You can find Matts version here : http://borkweb.com/story/bstat-search-cloud [...]



Some HTML is OK

or, reply to this post via trackback.