Announcement

Collapse
No announcement yet.

Popular threads widgets

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Popular threads widgets

    I'm sure this must be easy enough to do, if you know what you're doing.

    I'd like a couple of widgets showing the top five most viewed thread, or the top five threads with the most replies.

    I'm guessing there's some pretty straight forward code for these, can anyone help me out?

  • #2
    Are you wanting most viewed/most replies EVER, or over the last 30 days, year, etc? The code is going to vary depending on this.

    Comment


    • #3
      Oh yeah, I'd like the stats to be most viewed/most replies ever if that's possible.

      Comment


      • #4
        Have any ideas bszopi?

        Comment


        • #5
          Originally posted by Mr Jolly View Post
          Have any ideas bszopi?
          Crap, sorry. I missed your reply earlier. Lemme throw something together tonight for you.

          Comment


          • #6
            Ok, here is the code to place in a PHP eval widget for most viewed threads.

            PHP Code:
            global $vbulletin;
            $msglength 150;
            $dots '...';
            $thread $vbulletin->db->query_read("SELECT thread.threadid, thread.title, thread.views, post.pagetext AS message
            FROM " 
            TABLE_PREFIX "thread AS thread
            LEFT JOIN " 
            TABLE_PREFIX "post AS post ON (post.postid = thread.firstpostid)
            WHERE 1=1
            ORDER BY thread.views DESC
            LIMIT 0,5"
            );
            $row = array();
            if (
            $vbulletin->db->num_rows($thread) > 0
            {
                while(
            $rowthread $vbulletin->db->fetch_array($thread)){
                    
            $row[] = array(
                                
            'contentid'        => $rowthread['threadid'], 
                                
            'message'        => $rowthread['message'], 
                                
            'url'            => fetch_seo_url('thread'$rowthread),
                                
            'title'            => $rowthread['title'],
                                
            'views'            => $rowthread['views']);
                }
            }
            $static '<ul>';
            for(
            $i 0$i count($row); $i++)
            {  
                
            $static .= '<li>';
                    
            $static .= '<a href="' .$row[$i]['url'] . '"><b>' $row[$i]['title'] . '</b></a><br/> ';
                    
            $static .= '<span style="font-size:11px">(' $row[$i]['views'] . ' views)</span>';
                    if(
            strlen($row[$i]['message']) > $msglength)
                        {
                            
            $row[$i]['message'] = substr($row[$i]['message'],0,$msglength);
                            
            $row[$i]['message'] = substr($row[$i]['message'],0,strrpos($row[$i]['message']," ")) . $dots;
                        }
                    
            $static .= '<ul>';    
                        
            $static .= '<li>';
                            
            $static .= strip_bbcode($row[$i]['message'],true,true,false,true,false) . '<br/><br/>';
                        
            $static .= '</li>';
                    
            $static .= '</ul>';
                
            $static .= '</li>';
            }
            $static .= '</ul>';
            $output $static
            For most replies, just change every instance of 'views' to 'replycount'. I did minimal styling in there, but it should be pretty easy to figure out if you want to change it. Also, I didn't know exactly what all you wanted in there, so I just made some assumptions. Feel free to ask if you have questions on any of it.

            Comment


            • #7
              You sir are a gentleman and a scholar. I'll give it a try and have a play around with it. Thanks muchly.

              Comment


              • #8
                No problem.

                Comment


                • #9
                  bszopi, can you tell me how to exclude a forum from the results?

                  Comment


                  • #10
                    Originally posted by Mr Jolly View Post
                    bszopi, can you tell me how to exclude a forum from the results?
                    Sure. Inside the queryread, find WHERE 1=1 and after it, add:

                    PHP Code:
                    AND thread.forumid !=103 
                    Just replace 103 with the forum ID you want to exclude from the list.

                    Comment


                    • #11
                      Thanks, that's great.

                      Comment


                      • #12
                        I'm gonna sound like a pest, but how do I begin to style the widget?

                        I assumed I could just wrap it in one of the existing templates so the style matches perfectly, but unfortunately I'm not having any luck with that.

                        Comment


                        • #13
                          bszopi, this is a cool little block Tks for the script adn i have one question for you, can we add the title into the phrase manager and use it either in french or english as a varname and how to do so?!?
                          My forum is english and mostly french members but i want to keep both.
                          Up to know i didn't figure out how to automatically replace titles when they select language Any clue or pointers
                          tks

                          Comment


                          • #14
                            Mr. Jolly, can you expand on styling of the widget? Are you just trying to match font sizes and colors, or...? My reply to fxwoody might help you out?

                            fxwoody, the best way to do this would be to make a new template, and make some tweaks to it. The widget, as a default PHP widget, uses the following template: vbcms_widget_execphp_page. So create a new template (lets say, vbcms_widget_mostviewed), and copy/paste the execphp code into it. Next, you need to configure the widget to use your new template, so edit the widget and replace the template used with your newly created template. As of right now, since you just copied/pasted the original code, everything should work as before.

                            Now, create your new phrase. Edit your widget again, and at the top of the file replace
                            PHP Code:
                            global $vbulletin
                            with:
                            PHP Code:
                            global $vbulletin$vbphrase;
                            $rm $vbphrase['your_new_phrase']; 
                            replacing 'your_new_phrase' with your phrase name.

                            Edit your new template again, and replace
                            Code:
                            {vb:raw title}
                            with
                            Code:
                            {vb:rawphrase your_new_phrase}
                            That should do what you want.

                            Comment


                            • #15
                              Well, ideally it would look great if they looked just like the other widgets, they are a different font size, show the avatar etc..

                              I wanted to style it like the 'recent posts' widget, but it's not as simple as just using the same template and I'm not having any luck just trying to edit style classes into the template for the new widget.

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              X