Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Useful function when you are coding addons
hamoe
Join Date: Jul 2002
Posts: 10

 

oregon
Show Printable Version Email this Page Subscription
hamoe hamoe is offline 07-26-2002, 10:00 PM

Last night I coded the main page for http://www.fexboards.com, and before that I coded the tutorial database for that same site (organized very similar to this sites hack section, although I believe coded quite differently). I knew I was going to have to deal with a lot of repeating-element templates. By repeating-element templates, I mean templates such as the infamous postbit template, something which when its finally used, will be echoed out many times in a row in accordance with the results of a database query. The function I wrote has you supply a comma separated list of variables as they would appear in the database query, your master template name, your subtemplate name, the table(s) present in the from clause of the query, and the conditions under which the selection will take place (the where clause, you can also include order by and group by stuff here).

An example of its use is as follows:
PHP Code:
$mainpage[top10posters] = loop_template('userid,username,posts',
                                          
'mainpage','top10posters','user',
                                          
'order by posts desc limit 10'); 
That one function call right there will store all the iterations of the mainpage_top10posters template, filled with the top 10 posters' information, into $mainpage[top10posters]. That means after you run this you can just include your final template that just echoes out $mainpage[top10posters] where its needed.

The main limitation is that you cannot do any processing on the variables. If you wanted to loop through posts and you wanted to parse the pagetext with bbcodeparse(), you would have to hack up the function or just forget about using it. Nonetheless, I have found it pretty useful.

Comments/criticism/suggestions appreciated. The function is attached.
Attached Files
File Type: php loop_template.func.php (1.9 KB, 31 views)
Reply With Quote
  #12  
Old 07-31-2002, 12:54 AM
hamoe hamoe is offline
 
Join Date: Jul 2002
Location: oregon
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey I'm here. What I am wondering is why you don't just have that link in your template file....

PHP Code:
  $reviewb $DB_site->query("SELECT * FROM reviews");
  while(
$ra $DB_site->fetch_array($reviewb)) {


   eval(
"dooutput(\"".gettemplate("reviews_list")."\");");    

  } 

Can you not just have that link that I took out in your template? Here is how the function call would look:

loop_template("*", "reviews","list", "reviews");

In your template the variables will be available to you like this:

$reviews[list_fieldname]

All other variables you want to use that arent taken from the mysql query are just available how you would expect them.
Reply With Quote
  #13  
Old 07-31-2002, 12:57 AM
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
Posts: 1,926
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks man, you are the coolest person around, can you help me further on aim, if you have it

my friend sat ScapeStudio, I am at his house

Thanks
Reply With Quote
  #14  
Old 07-31-2002, 01:14 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cool...

Satan
Reply With Quote
  #15  
Old 07-31-2002, 03:24 AM
SaintDog SaintDog is offline
 
Join Date: Nov 2001
Location: Tennessee
Posts: 1,975
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by hamoe
I just realized this would probably do better in the Hacking Hints and Tips forum. If some bored mod feels like moving it for me it would be appreciated
Bored....Moved....


- SaintDog
Reply With Quote
  #16  
Old 08-01-2002, 05:36 AM
hamoe hamoe is offline
 
Join Date: Jul 2002
Location: oregon
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol, thanks saintdog, i knew someone would get bored eventually
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 08:49 AM.


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.05880 seconds
  • Memory Usage 2,278KB
  • Queries Executed 21 (?)
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
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (1)postbit_attachment
  • (6)postbit_onlinestatus
  • (6)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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete