Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - MOD: Most Recent Posts
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MOD: Most Recent Posts

 Post Reply Post Reply Page  123 5>
Author
MrMellie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 December 2006
Location: United Kingdom
Status: Offline
Points: 251
Post Options Post Options   Thanks (0) Thanks(0)   Quote MrMellie Quote  Post ReplyReply Direct Link To This Post Topic: MOD: Most Recent Posts
    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>
  • Back to Top
    MrMellie View Drop Down
    Senior Member
    Senior Member
    Avatar

    Joined: 12 December 2006
    Location: United Kingdom
    Status: Offline
    Points: 251
    Post Options Post Options   Thanks (0) Thanks(0)   Quote MrMellie Quote  Post ReplyReply Direct Link To This Post 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.
    Back to Top
    MrMellie View Drop Down
    Senior Member
    Senior Member
    Avatar

    Joined: 12 December 2006
    Location: United Kingdom
    Status: Offline
    Points: 251
    Post Options Post Options   Thanks (0) Thanks(0)   Quote MrMellie Quote  Post ReplyReply Direct Link To This Post 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.

    Edited by MrMellie - 05 February 2007 at 12:36pm
    Back to Top
    MrMellie View Drop Down
    Senior Member
    Senior Member
    Avatar

    Joined: 12 December 2006
    Location: United Kingdom
    Status: Offline
    Points: 251
    Post Options Post Options   Thanks (0) Thanks(0)   Quote MrMellie Quote  Post ReplyReply Direct Link To This Post 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.
    Back to Top
    Pfeff View Drop Down
    Newbie
    Newbie


    Joined: 17 October 2006
    Status: Offline
    Points: 14
    Post Options Post Options   Thanks (0) Thanks(0)   Quote Pfeff Quote  Post ReplyReply Direct Link To This Post Posted: 07 February 2007 at 1:56am
    Nice!
    Back to Top
    suedechaser View Drop Down
    Groupie
    Groupie


    Joined: 25 February 2006
    Location: USA
    Status: Offline
    Points: 129
    Post Options Post Options   Thanks (0) Thanks(0)   Quote suedechaser Quote  Post ReplyReply Direct Link To This Post 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
    Back to Top
    MrMellie View Drop Down
    Senior Member
    Senior Member
    Avatar

    Joined: 12 December 2006
    Location: United Kingdom
    Status: Offline
    Points: 251
    Post Options Post Options   Thanks (0) Thanks(0)   Quote MrMellie Quote  Post ReplyReply Direct Link To This Post 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?

    Back to Top
    suedechaser View Drop Down
    Groupie
    Groupie


    Joined: 25 February 2006
    Location: USA
    Status: Offline
    Points: 129
    Post Options Post Options   Thanks (0) Thanks(0)   Quote suedechaser Quote  Post ReplyReply Direct Link To This Post 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
    Back to Top
     Post Reply Post Reply Page  123 5>

    Forum Jump Forum Permissions View Drop Down

    Forum Software by Web Wiz Forums® version 12.08
    Copyright ©2001-2026 Web Wiz Ltd.


    Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
    About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

    Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
    Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

    Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

    Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.