Print Page | Close Window

MOD: Most Recent Posts

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums Modifications
Forum Description: Mod's and Add-on's for Web Wiz Forums.
URL: https://forums.webwiz.net/forum_posts.asp?TID=22604
Printed Date: 28 March 2026 at 5:52am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: MOD: Most Recent Posts
Posted By: MrMellie
Subject: MOD: Most Recent Posts
Date Posted: 05 February 2007 at 11:47am
Oh No! Not another "Latest Topics" Mod!?!? Well, yes sort of, sorry! I've created a new thread for my adaption of the code from MSSQL Top 10 Latest Posts because it's evolved a long way from what was in the original post. I've also been constantly updating it to add missing features and make it more flexible and it'll be easier for anyone who is using my version of this mod to keep track of updates.

This Mod works on ALL database backends and has configuration options for user customisation. It can be used on pages external to the forum (e.g. your website's main default.asp) or be included on the WWF default.asp


v1.1 Changes:

  • Now uses proper database boolean global variable instead of hard coded values.
  • Message preview cleaned up to prevent HTML or forum tags breaking the display.
  • Added missing variable declarations.
  • Added option to specifiy which forums posts are shown from.
  • Optimised code for faster processing.
  • Now only shows post from Forums the user has permissions to.
  • Added direct link to forums when used on external pages. (thanks to Pfeff for that idea)
  • Added forum table into the query to allow people to customise more easily.


    Instructions

    There is a constant in the file, intStyle, that you can set to toggle between two different query types, true most recent posts, or most recent topics posted to. Change the constant intTop to pull back the number of recent posts you require. Default is 10. If you only want to only display posts from specific forums, find this line:

    'strSql = strSql & "AND T.Forum_ID IN (x,y,..) "

    Uncomment it and replace the "x,y,.." portion with a comma delimited list of forum ID's that you want to view posts from.

    You will also need to put the following in your default.asp home page (not the forum default, but the main one for your site). At the top of the file:

    <!--#include file="forum/common.asp" -->
    <!--#include file="forum/functions/functions_date_time_format.asp" -->


    Change the directory name (here I've used "forum") to suit where your forum sits within your site.

    Then add:

    Response.Write "<link href=""forum/" & strCSSfile & "default_style.css"" rel=""stylesheet"" type=""text/css"" />"& vbNewline

    somewhere in your html header statement. You may not need to use the response.write part of the statement depending how you prefer to code your pages. Don't forget to change the directory name for your forum again!

    Lastly add:

    <!--#include file="forum/recent_posts.asp"-->

    at the point you require the Most Recent posts to appear.

    You can also use this file to show the Most Recent posts on your forum default page. Depending on where you put the include, you might need to comment out the "Call closeDatabase" command in default.asp. An example of when you would need to do this is if you placed the MRP panel before the What's Going On? panel.

    If you get the following error, you haven't commented out the closeDatabase line in default.asp!!

     
    Quote

    Microsoft VBScript runtime error '800a01a8'

    Object required

    /forum/default.asp, line xxx

    which is this line...
     
    rsCommon.Open strSQL, adoCon



    Mod Code v1.1


    <%
    '#########################################################################
    '#
    '# Most Recent Posts Mod for Web Wiz Forums
    '# V1.1
    '#   
    '# Author: Ric Naylor aka MrMellie
    '#
    '# Web Wiz Forums - Copyright ©2001-2006 Web Wiz. All Rights Reserved.   
    '# http://www.webwizforums.com
    '#
    '########################################################################

    Dim strPostDate
    Dim strPostTime
    Dim strShtMess
    Dim saryTopxx
    Dim intRows
    Dim fld_Subject
    Dim fld_Topic_ID
    Dim fld_Views
    Dim fld_Date
    Dim fld_Author
    Dim fld_Thread_Id
    Dim fld_Message
    Dim i

    '### Set intStyle to give the required output.
    '### 1 = Top xx latest posts, regardless of which Topic they appear in (gives a true Top xx posts, but some might share the same Topic)
    '### 2 = Top xx latest Topics that have been posted to (gives unique Topics).
    const intStyle=1

    '### Set this variable to the number of topics you wish to display.
    const intTop = 10

    strSql = "T.Subject, T.Topic_ID, T.No_of_views, Th.Message_date, Au.Username, Th.Thread_ID, Th.message " & _
            "FROM " & strDbTable & "Forum F" & strDBNoLock & " " & _
            "INNER JOIN (" & strDbTable & "Permissions P" & strDBNoLock & " " & _
            "INNER JOIN (" & strDbTable & "Topic T" & strDBNoLock & " " & _
            "INNER JOIN (" & strDbTable & "Thread Th" & strDBNoLock & " INNER JOIN " & strDbTable & "Author Au" & strDBNoLock & " " & _
            "ON Th.Author_ID=Au.Author_ID) "
    if intStyle=1 then       
        strSql = strSql & "ON T.Topic_ID=Th.Topic_ID) "
    else
        strSql = strSql & "ON T.Last_Thread_ID=Th.Thread_ID) "
    end if
        strSql = strSql & "ON T.Forum_ID=P.Forum_ID) "
        strSql = strSql & "ON P.Forum_ID=F.Forum_ID "
    strSql = strSql & "WHERE T.Hide="& strDBFalse & " AND Th.Hide=" & strDBFalse & " AND (P.View_Forum=" & strDBTrue & " AND (P.Group_ID = " & intGroupID & " OR P.Author_ID = " & lngLoggedInUserID & ")) "

    '### Uncomment the next line to select Topics from specific Forums.
    '### Replace "x,y,.." with a comma delimited list of forum numbers or a single forum number.
    'strSql = strSql & "AND T.Forum_ID IN (x,y,..) "

    strSql = strSql & "ORDER By Th.Message_date DESC "
    if strDatabaseType = "mySQL" then strSql = "SELECT DISTINCT "& strSql & "LIMIT "& intTop else strSQL = "SELECT TOP " & intTop & " " & strSQL

    rsCommon.Open strSQL, adoCon
    saryTopxx = rsCommon.GetRows()

    '### If you include this page on the forum default.asp you will need to comment out the Call closeDatabase line
    '### if you place it before the Whats Going On panel.
    'Clean up
    Call closeDatabase()

    intRows = UBound(saryTopxx, 2)

    fld_Subject = 0
    fld_Topic_ID = 1
    fld_Views = 2
    fld_Date = 3
    fld_Author = 4
    fld_Thread_Id = 5
    fld_Message = 6
    %>

    <table cellspacing="1" cellpadding="3" class="tableBorder" align="center">
    <tr class="tableLedger">
    <td colspan="5">Most Recent Posts
    <!--Remove the following line if you include this on the WWF default.asp page as it's superfluous in that case-->
    - <a href="<% =strForumPath%>">Go to Forums Now!</a>
    <!--End Remove -->
    </td></tr>
    <tr class="tableSubLedger">
    <td width="25%" align="center">Topic</td>
    <td width="33%" align="center">Message</td>



  • Replies:
    Posted By: MrMellie
    Date Posted: 05 February 2007 at 11:58am
    Originally posted by Pfeff Pfeff wrote:


    Is it possible to include posts from category ID?I have a forum about sports. I have a category on hunting. I have 8 hunting subforums.On the hunting index page I want to include the top 10 posts from the hunting category.


    Pfeff, to include only items from a certain category, then uncomment this line:


    'strSql = strSql & "AND T.Forum_ID IN (x,y,..) "

    and change it to:

    strSql = strSql & "AND F.Cat_ID IN (x,y,..) "

    Replace "x,y,.." with the required category ID or ID's. That should do the trick.


    Posted By: MrMellie
    Date Posted: 05 February 2007 at 12:35pm
    Originally posted by bitbyter bitbyter wrote:

    o.k it's a great mod MR Mellie. thanks for it!    

    i'd like to see in which (sub)forum the message is posted instead of seeing the beginning of the message . is there an easy way to change this?


    Use the version of code above and replace Th.message in the first line of the strSQL definition and replace it with F.Forum_name.

    Remove the line that cleans up the code in the message:

    strShtMess = removeHTML(saryTopxx(fld_Message,i), 40, True)

    and that is basically it. You can then add a hyperlink around the forum name if you want.


    Posted By: MrMellie
    Date Posted: 05 February 2007 at 12:48pm
    Originally posted by PrivateEye PrivateEye wrote:

    MR Mellie, I tried your code to get top 10 forum names only (not posts/topics in forums). But if users post 10 posts in one forum, this one forum is displayed 10 times. I am not good in SQL grouping, can you please help me and write the query to get true top 10 forum names. I will be thankful to you.
    So you want to show just the forum name for the top 10 most recently posted to forums? That'd be incredibly simple as you'll only need the permissions table and forum table in the query. Use last-post_date to make the top 10 selection.


    Posted By: Pfeff
    Date Posted: 07 February 2007 at 1:56am
    Nice!


    Posted By: suedechaser
    Date Posted: 14 February 2007 at 5:29am
    Hi Mr Mellie,

    Could you provide a list of what the original table names are in StrSQL please? I keep getting an error

    Microsoft VBScript runtime error '800a01a8'

    Object required

    /forum/mrp.asp, line 58

    ... and assume that the problem may be that STRSQL had nothing in it because of the different table names in your query.

    I tried to substitute the t's, th's , au's with "topic", "thread" etc but could not get it to work.

    As no-one else has posted about this - am I missing something entirely different here?

    thanks

    suede


    Posted By: MrMellie
    Date Posted: 14 February 2007 at 11:15am
    The table names are all in there in the FROM and JOIN clauses e.g. "FROM " & strDbTable & "Forum F". The aliases reduce the amount of string concatenations required to build strSQL as concatenations drastically slow down ASP processing.

    However, I think your problem is something different. Have you included the file on the main forum default page? Did you put it after the 'call Closedatabase' command in default.asp?



    Posted By: suedechaser
    Date Posted: 02 March 2007 at 4:58am
    Hi Mr Mellie,

    I got this to work - OK

    When I change intstyle from 1 to 2, it doesn't show topics only - just stays the same and shows latest posts.

    What could be the issue?

    regards

    suede


    Posted By: MrMellie
    Date Posted: 02 March 2007 at 9:56am
    Hmm sounds odd. It's not something simple like every new post on the forum you're using happens to be in a different Topic anyhow? If you add two new posts to one Topic, what does it show?


    Posted By: mconway72
    Date Posted: 04 March 2007 at 9:29pm
    This is outstanding!!!  Finally a "most recent" mod that works for me ... thanks, MrMellie!!!
     
    I have only one tweak to this, but have not figured it out myself.  How do I remove the Message and Date columns and fields?  I would like only to display Topic, Author and Views.  Help!


    Posted By: MrMellie
    Date Posted: 05 March 2007 at 2:25pm
    Hi mconway, All you need to do is remove the following lines from the file:

           Response.Write "<td><span class=""smText"">" & strShtMess & "</span></td>"

    and

           Response.Write "<td align=""center""><span class=""smText"">" & strPostDate & "-" & strPostTime & "</span></td>"


    Posted By: mconway72
    Date Posted: 08 March 2007 at 2:31am
    MrMellie your code is awesome. we quickly got it up and running on our site.  We seem to have an issue where users with Firefox get the top 5 posts posted twice.  IE users get the top 10 posts and no doubles so it works great under ie, but not so under Firefox.
     
    Thank you very much and keep up the great work


    Posted By: mconway72
    Date Posted: 08 March 2007 at 2:36am
    MrMellie >>>
     
    Thank you.  I figured that out, but it took me a long time.  Though i think i might have done it differently, so i will go back make sure it is done your way
     
    thank you very very much!!!


    Posted By: suedechaser
    Date Posted: 11 March 2007 at 10:35pm
    Hi Mr Mellie,

    Yes, every new post was in a different topic - silly me!

    kindest regards

    suede


    Posted By: nsomniac
    Date Posted: 14 March 2007 at 5:45am
    Hi Mr Mellie,

    Your mod works great, but was just wondering why it formats to a different style than the rest of the forum? I mean by font, background color of tables... is there a way to get it to keep to the same style as the forum proper?


    Posted By: nsomniac
    Date Posted: 14 March 2007 at 6:31am
    Hi

    Is it possible to add this code twice into the forum so that I can have both last 10 active topics and last 10 new posts?

    I tried to rewrite and change some variable and commented out the repeated naming of variables... ie commented out all the second Dim's and changed the constants intStyle to intStyle2 and so on... but i'm getting an error still....

    ADODB.Recordset error '800a0e79'

    Operation is not allowed when the object is open.

    /Default.asp, line 909


    Something to do with rsCommon.Open???


    Sorry, not very good at coding and have no idea about asp, but just wondering if anyone can help at all?




    Posted By: MrMellie
    Date Posted: 15 March 2007 at 11:24am
    Originally posted by nsomniac nsomniac wrote:

    Hi Mr Mellie,

    Your mod works great, but was just wondering why it formats to a different style than the rest of the forum? I mean by font, background color of tables... is there a way to get it to keep to the same style as the forum proper?
    Ummmm... It should look the same. It uses the forum style classes so everything, colour, fonts etc, should be the same. Confused Have you got a link to an example where it's not doing that?
     
     


    Posted By: MrMellie
    Date Posted: 15 March 2007 at 11:27am
    Originally posted by nsomniac nsomniac wrote:

    I tried to rewrite and change some variable and commented out the repeated naming of variables... ie commented out all the second Dim's and changed the constants intStyle to intStyle2 and so on... but i'm getting an error still....
    Sounds like you're on the right track. In place of the first "call closeDatabase" command, try putting rsCommon.Close. This will leave the connection open and have the recordset in a state ready for the second query to run.


    Posted By: nsomniac
    Date Posted: 15 March 2007 at 9:46pm
    Hi MrMellie,

    The CSS is the same, sorry, my mistake... but its just that the topics and posts are written in a smaller size font.

    http://www.usyddental.com - http://www.usyddental.com

    at the bottom of the page....

    Do you know where in the css file that I can change this to be the same size font as the rest of the page??


    Posted By: MrMellie
    Date Posted: 16 March 2007 at 9:27am
    Aaah, ok I get you now. You don't need to modify the CSS as that will affect other bits of the forum. If you take out the bits of code that say:
     
    <span class=""smText"">
     
    then it should appear in the default font size. Let me know how you get on as I haven't tested this, but pretty sure it should work.


    Posted By: nsomniac
    Date Posted: 20 March 2007 at 5:48am
    Thanks MrMellie,

    All has worked out well,

    the rscommon.close phrase worked perfectly and i removed all the <smtext> coding as well as the <smlink> coding in the link part of the tables. Worked perfectly!

    Thanks


    Posted By: rmusictv
    Date Posted: 30 March 2007 at 5:48pm
    I have tried to addf this to my forum (its working), but I keep getting the below message at the bottom of my forum.
     
     
    ------------------------------------------------------------------------------------
    Microsoft VBScript runtime error '800a01a8'

    Object required: 'adoCon'

    /forum/database/database_connection.asp, line 269

    ------------------------------------------------------------------------------------
     
    Heres the link to the forum......scroll below to see what I mean.
     
    How do I fix it?
     
    Have I put the code in the wrong place? If yes, where should I put it?
     
    PLEASE HELP!!!!!
     
     


    Posted By: MrMellie
    Date Posted: 02 April 2007 at 9:19am
    Did you comment out the "call closeDatabase" line in default.asp?


    Posted By: Praveen
    Date Posted: 25 June 2007 at 2:09am
    Hi I have a small problem. When there are no posts in the particular forum or the user does not have the permission, I get like this:
    Quote
    Error Type:
    ADODB.Recordset (0x800A0BCD)
    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
    /works2007/enggsite/stuforum/recent_news_inc.asp, line 38
     
    Line 38:
    saryTopxx = rsCommon.GetRows()
     
    Please explain me what to do.


    -------------


    Posted By: MrMellie
    Date Posted: 25 June 2007 at 9:34pm
    Ok, not seen this before, I'll take a look.


    Posted By: Praveen
    Date Posted: 26 June 2007 at 7:27pm
    But somehow I got it corrected,, Hmmm donno..

    -------------


    Posted By: Marconny
    Date Posted: 27 June 2007 at 5:40am
    Hi all
     
    I have this kind of problem with this great MOD. It works great if I have one category of forum, but if I put more than one forum category it returns this error:

    Microsoft VBScript runtime error '800a0411'

    Name redefined: 'intStyle'
    /forum/default.asp, line 816
     
    Please help Confused


    Posted By: Praveen
    Date Posted: 27 June 2007 at 5:56am
    ya pls take away that const intStyle

    -------------


    Posted By: Marconny
    Date Posted: 27 June 2007 at 7:30am

    How do you mean that? I tried to delete it but it still don work!

    Thanks


    Posted By: billd3
    Date Posted: 28 June 2007 at 3:38pm
    I've created the recent_posts.asp by copying the code, saved it to my /forum/ folder, added the include, when  do, I get a server error.
    Yes, I commented out that close statement like suggested.
    We want the 10 most recent posts from any forum that is not a hidden forum listed somewhere so that the visitors can click and see the 10 most recent posts in all public forum (not the hidden moderator discussion area).

    This is the site:
    http://theamcforum.com/forum/default.asp

    We want a situation similar to:
    View the http://cgi.amcforum.net/cgi-bin/yabb2/YaBB.pl?action=recent - 10 most recent posts of this forum.
    when they click, they get the 10 most recent posts in any forum or section.

    I did a copy n paste of the code in page one of this thread, saved it in FrontPage as recent_posts.asp, added the include, commented the one line as suggested and WHAM, the thing crashes.
    We have the very most recent, 8.06 or whatever, just downloaded like on 6/25/07 so maybe THAT's it?

    MS SQL database.


    -------------
    BillD
    http://theamcpages.com
    http://theamcforum.com


    Posted By: Epperson
    Date Posted: 13 July 2007 at 7:29am
    Having an issue where it is showing 2 latest posts for each reply.
     
    Sure it is something simple I am overlooking.
    Thanks in advance.
     
    http://www.surplus.cc/Board/default.asp - http://www.surplus.cc/Board/default.asp
     
    Scroll to the bottom of the page


    -------------
    http://www.surplus.cc


    Posted By: annudora
    Date Posted: 29 August 2007 at 12:08pm
    it works fine but i had a problem with characters. Turkish chars are not seen like below. Can we fix this.



    i am using forum in forum folder. and INCLUDE this recent posts file in the root folder.


    Posted By: spidi man
    Date Posted: 31 August 2007 at 9:19pm
    hi

    how can i see the name of the forum in every message that shows up ?

    Thanks !


    Posted By: suedechaser
    Date Posted: 08 October 2007 at 12:36am
    HI all,

    This one is for the SQL gurus...

    Using this part of MM's SQL
    <snip>

    strSql = strSql & "ON T.Forum_ID=P.Forum_ID) "
        strSql = strSql & "ON P.Forum_ID=F.Forum_ID "
    strSql = strSql & "WHERE T.Hide="& strDBFalse & " AND Th.Hide=" & strDBFalse & " AND (P.View_Forum=" & strDBTrue & " AND (P.Group_ID = " & intGroupID & " OR P.Author_ID = " & lngLoggedInUserID & ")) "

    </snip>

    ...I have been unsuccessful at putting a date parameter to show posts on or before today ( for the last calendar year ) on the end of the strSql. My last attempt, of many, is this:

    Declaration at top of page - BeginDate = YEAR(dtmNow)

    strSql = strSql & "WHERE YEAR(Th.Message_date) <= BeginDate "

    Can someone please explain where I am going wrong?

    Kind regards

    Suede


    Posted By: suedechaser
    Date Posted: 09 October 2007 at 12:45pm
    ...bump...

    Is there noone who can help me please?


    Posted By: coolguy
    Date Posted: 26 June 2008 at 10:03pm
    Hello MrMellie, I use this MOD and it works great, what do I need to do to customize it to pull Top xx latest posts for a particular user?



    Print Page | Close Window

    Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
    Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net