Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2003, 12:28 AM
karmanis karmanis is offline
 
Join Date: Jun 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default ...Last5posts instead of Lastpost, in Forumdisplay !

(a screenshot is attached at the end from a commercial site running vb)

Motivation: In newly created communities you have not many posts. So insted of demonstrating the number of posts, threads, and the lastpost for each forum, why not just serving the last 5 posts ? It gives the feeling that your board is active and the user is tempted to follow some links, so he will probably stay in the board for a while. :bunny:

Imagine a board with only 1000 posts ... with the number of posts beside the forums it seems almost empty. Using the last5posts bit, the user is not informed about the number of the posts, instead he is being served with some interesting links/threads to follow!



The stuff:
Let me describe what I have achieved so far about this.. clarifying that I have no knowledge of php or sql (however, I am fluent in some OOP). :alien:

Normally, in forumdisplay>forumbit_level1/2_post templates, the variable $forum[lastpostinfo] is called. This variable is evaluated in forumdisplay.php inside a while loop that generates all the info needed to display each row for the catecorized forums when foromdisplay is called. So, inside this loop you have $forum[forumid] stating the current forum proccessed in cache.

My idea was to nest another variable inside this loop that would run a query (Zzed helped me with this in this thread ) and get the last 5 posts for the currently proccessed forum.

The difficult part is that you don't have one thing to show but 5. The way I went was to make a function (assigned to our $last5posts) that would manage to parse the lastposts table and display the results with html links.

However, I found that "functions inside functions" (the main loop) is not a good idea in php, so I had to place my function outside the makeforumbit function that manages the loop for the displayed forums.

PHP Code:
//*********
$getlast5posts'';
function 
showlast5posts($forumpath,$forumid){
global 
$DB_site;
$templatesused='forumhome_lastpostby';
$last5postsshow='';
        
$getlast5posts=$DB_site->query("SELECT threadid,title FROM thread WHERE forumid = $forumid 
ORDER BY lastpost DESC limit 5"
);



        while(
$this5post=$DB_site->fetch_array($getlast5posts)) {
                     
$forumspathe=$forumspath;
                     
$tid=$this5post[threadid];
                     
$ttitle=$this5post[title];
                     eval(
"\$last5postsshow = \"".gettemplate('forumhome_lastpostby')."\";");
                    
        }

...and I state the guilty variable inside function makeforumbit ..

PHP Code:
$last5posts=showlast5posts($forumpath,$forum[forumid]); 
The template used (forumhome_last5posts) is just:

Code:
	<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr align="right">
		<td nowrap><smallfont>

<a href=\"$forumspath/showthread.php?s=&threadid=$tid\">$ttitle</a>

	</smallfont>
</td></tr></table>
<br>

The bad news : This crap does not show anything.

The good news: If you replace the "eval" with an echo ... :knockedout:

PHP Code:
echo "<font face=\"Verdana\" size=\"2\">-> <a href=\"$forumspath/showthread.php?s=&threadid=
$this5post[threadid]\">$this5post[title]</a></font><br>"
...it shows you perfectly the last5posts, but with a little problem: it brings them to the start of the page insted inside the appropriate table we want.

here comes...
The request:
Could someone of you, the php/sql/vb-mods experts, take a look at forumdisplay code and find the magick trick that would enbody the functionality the screenshot describes ? :lick:

many thanks ! (honestly)
Attached Images
File Type: jpg last5posts_beside_forumname.jpg (41.6 KB, 0 views)
Reply With Quote
  #2  
Old 08-02-2003, 04:56 PM
jamslam's Avatar
jamslam jamslam is offline
 
Join Date: Feb 2003
Location: Massachusetts
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well firstly, you know that you will be looping the template 5 times, right? meaning you have FIVE tables instead of one... so you probably shouldn't use a table in your template, just the link, followed by a <br />

AND are you putting the $last5postsshow in the forumdisplay template to be displayed?

Also, you need to eval EVERY variable u use in your templates... so it should look like this...

Code:
        while($this5post=$DB_site->fetch_array($getlast5posts)) { 
                     eval("\$forumspathe = \"".$forumspath."\";"); 
                     eval("\$tid = \"".$this5post[threadid]."\";"); 
                     eval("\$ttitle = \"".$this5post[title]."\";"); 
                     eval("\$last5postsshow = \"".gettemplate('forumhome_lastpostby')."\";"); 
                     
        }
now you will be able to use those variables in forumdisplay templates... also, you should edit your lastpostby template to JUST a link, because remember, that's the template that will be repeated 5 times, so if you have a table in there, there will be five tables... or if you absolutely need a table, put this in the forum display

Code:
<table>
$last5postsshow
</table>
then in the lastpostby template....

Code:
<tr>
  <td> -- YOUR LINK TO POST -- </td>
</tr>
i hope this helps
Reply With Quote
  #3  
Old 08-02-2003, 10:10 PM
karmanis karmanis is offline
 
Join Date: Jun 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks jamslam,

I'll take a further look at it to find out what happens with the templates. :cross-eyed:
Reply With Quote
  #4  
Old 08-02-2003, 10:40 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Firstly, you don't need to eval all those variables. Remember that the scope of all those variables is local to that function, this results in the problem of nothing showing:

PHP Code:
function showlast5posts($forumpath$forumid){ 
    global 
$DB_site

    
$getlast5posts $DB_site->query("    SELECT threadid, title 
                                        FROM thread 
                                        WHERE forumid = '"
.intval($forumid)"'
                                        ORDER BY lastpost DESC 
                                        LIMIT 5"
); 



        while(
$this5post $DB_site->fetch_array($getlast5posts)) { 
            
$forumspathe $forumspath
            
$tid $this5post['threadid']; 
            
$ttitle $this5post['title']; 
            eval(
"\$GLOBALS[last5postsshow] = \"".gettemplate('forumhome_lastpostby')."\";"); 
                     
        } 

The above is more like what you want. Also note that $templatesused only works before you have required global.php, so add the template along with the others at the top. Secondly I think using this method is very bad, especially if you have alot of forums as this adds one query per forum.
Reply With Quote
  #5  
Old 08-03-2003, 12:18 AM
karmanis karmanis is offline
 
Join Date: Jun 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am concerned of the many queries, and my worst fear is the case that I would need an additional query in the loop, to get the last threads not only from forumid but from it and all its child-forums aranoid:

Is there a way that I could modify the already used query to also include the subforums of $forumid ???

Code:
$getlast5posts=$DB_site->query("SELECT threadid,title FROM thread 
WHERE forumid = $forumid 
ORDER BY lastpost DESC limit 5");
I don't know much of sql, but of what I can see the Thread table has nothing relevant to "child forums" or a "parentid", which would be of some help. Any ideas ?



many thanks
Reply With Quote
  #6  
Old 08-03-2003, 06:16 AM
jamslam's Avatar
jamslam jamslam is offline
 
Join Date: Feb 2003
Location: Massachusetts
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Yesterday at 07:40 PM NTLDR said this in Post #4
Firstly, you don't need to eval all those variables. Remember that the scope of all those variables is local to that function, this results in the problem of nothing showing:

PHP Code:
function showlast5posts($forumpath$forumid){ 
    global 
$DB_site

    
$getlast5posts $DB_site->query("    SELECT threadid, title 
                                        FROM thread 
                                        WHERE forumid = '"
.intval($forumid)"'
                                        ORDER BY lastpost DESC 
                                        LIMIT 5"
); 



        while(
$this5post $DB_site->fetch_array($getlast5posts)) { 
            
$forumspathe $forumspath
            
$tid $this5post['threadid']; 
            
$ttitle $this5post['title']; 
            eval(
"\$GLOBALS[last5postsshow] = \"".gettemplate('forumhome_lastpostby')."\";"); 
                     
        } 

The above is more like what you want. Also note that $templatesused only works before you have required global.php, so add the template along with the others at the top. Secondly I think using this method is very bad, especially if you have alot of forums as this adds one query per forum.
sorry about that.. i'm new to PHP myself, i thought u would've had to eval those variables in order to use them in templates...

i missed the global thing to, i get caught on that a lot, sorry about the false info
Reply With Quote
  #7  
Old 08-03-2003, 12:59 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@jamslam: Don't worry about making mistakes as long as you learn from them

@karmanis: IMO the best way to achive this would be smiliar to Scott's hack that does this for the latest thread and modify it to store the last 5 instead of the last 1.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03999 seconds
  • Memory Usage 2,293KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (1)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete