The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Querying MySQL and echo-ing variables
Hello!
I'm developing a front page for a vbulletin powered forum. On the front page I mention the main Forum titles and their sub-forums. I do not wish to hardcode the titles so the webmaster can change this when needed. So I want to perform a MySQL query to retrieve the Forum titles: Code:
$results = $db->query_read("SELECT title FROM forum WHERE forumid = 1"); Also, I need to echo the contents of the Code:
$results Thanks for your help!! Jerry |
#2
|
|||
|
|||
When you say you're developing a front page, what are you doing exactly? Are you making a template? If so then yeah, you can't put php code in a template. The vbulletin way to do it is to write code in a plugin (or create your own page by writing a php file), then use templates to produce the output.
|
#3
|
|||
|
|||
Hi kh99,
I'm developing a theme indeed. I've duplicated the default theme and I am restyling and recoding the header, footer and the cms template. I'm now working in the vbcms_page template. Here I want to echo the forum titles with some nice styling around it. If i understand you correct I can just create a regular php file where I start with <?php and close the code with ?> ? This file then needs to be included as a plugin? --------------- Added [DATE]1312905358[/DATE] at [TIME]1312905358[/TIME] --------------- Or is there a direct variable which will output the forum titles? |
#4
|
|||
|
|||
If there isn't already a variable (and I'm not sure because I'm not familiar with that page), then you need to create a plugin, which is some php code that gets executed at some point in the vb script. That plugin code would have to do your query to set a variable, then register that variable in the vbcms_page template.
When you create a plugin you need to choose a hook location, which corresponds to a certain point in the vb script. Unfortunately I don't know much about that template so I don't know what hook location you should use. Maybe someone else does, or if I get time later I'll look. (Edit: Some people look at the list of hook locations and guess or fid one by trial and error, but if you know some php then I think the best way is to look at the vb php files and find a call to fetch_hook() that's in a place you can use). BTW, you can also just edit the vb php files to do what you want, but it's much better to use plugins because you can then upgrade without making the same changes to a new set of files. |
#5
|
|||
|
|||
Thanks again for your fast response! I'm going to read into hooks and plugins now. If I find out about the hooks used in this particular template I'll post it here. If you find out anything, please let me know as well.
Many thanks! --------------- Added [DATE]1312909240[/DATE] at [TIME]1312909240[/TIME] --------------- Hi kh99, To be honest, I don't quite get the whole idea of hooks. If i go to the theme editor Styles & Templates > Style Manager > Edit Templates > vBulletin CMS templates > vbcms_page I see the structure of a normal web page here. Some external parts are included like so: Code:
{vb:raw header} {vb:raw navbar} I went through the list of hooks for the cms, but I'm not even sure what I'm looking for. Thanks! |
#6
|
||||
|
||||
The hooks are for inserting PHP code. If you want to insert directly into the tempalte it will have to be HTML, javascript or CSS references external sheets.
|
#7
|
|||
|
|||
Quote:
One thing you can do is write an external php script to do what you want, then include it using instructions from the vbulletin manual: https://www.vbulletin.com/docs/html/..._externalfiles . But that's really to allow existing php scripts to be used without rewriting them, and you probably wouldn't want to write new stuff that way. But you could use the same idea - use that hook location, put in your query instead of the ob_start/ob_end thing, and when you have a variable set, use the preRegister line like in that example. The downside of that is that it will do that work on every page instead of just the page that is using it, but you could get it working then worry about the efficiency later. Edit: like PHP Code:
|
#8
|
|||
|
|||
Thanks a million for your help and explanations, kh99. It is starting to make sense now. I will first try getting it to work the 'correct' way through hooks and plugins.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|