MyBB Community Forums

Full Version: Adding Queries to MYBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Forgive me as I am new to MYBB but I am trying to modify my template to fit my websites theme. It is going well but I have been unable to figure out how (to add queries to/ call queries from) the templates. Right now all of my new code it just in the footer, header and index rows of the templates table. I am going to have a navigation menu on the left that is the same as the rest of my websites theme. I need to run a query to return the links so the only place have to update links is in my db not on every page. No problem with PHP but I know I can’t use PHP within the templates and don’t want to because of the holes it causes.

I have searched the MYBB site and I have been unable to find any documentation that explains this whole process. I have found bits and pieces but I haven’t been able to put it all together yet. My website is http://www.bighostingproviders.com/forum/. Any help would be great

Thanks
You can't do that directly in the templates. You will have to create a small plugin that runs that query, stores the results and then proceeds to edit the templates. See [Wiki: Database_Methods] (Broken link, head over to docs.mybb.com instead) for information on how to access the database. You might also want to take a look at [Wiki: Authoring_Plugins] (Broken link, head over to docs.mybb.com instead) for some documentation on plugins.
Suggest you find a similar acting plugin from the mods database and review the code. If you know PHP you'll understand quickly how MyBB works.
I understand PHP just fine. My problem isnt writing the query or php. My question is how do i access the query from the template? and how do i include the php file from the index.php. so lets say i put a file in the in folder. I wanna do something like

php-start
include inc/custom.php
php-end

in the index file

then have something like


php-start
function ect... query ect...
php-end

in the custom.php file

and my question is more around what i need to do in the template code to access that query?

Thanks
Again..

Suggest you find a similar acting plugin from the mods database and review the code.

With MyBB you'll place a variable in a template like {$foobar} and you'll hook into MyBB with a plugin hook.

There is a hello.php in the plugins folder that's a very bare bones plugin example but you're better off downloading an existing plugin for a real world example.
Exactly how to create new template variables? == Good question which I need to be able to answer in the future.*
*For an easy answer see below

(2012-04-03, 12:10 AM)soccer58us Wrote: [ -> ]...
and my question is more around what i need to do in the template code to access that query?...

Easy answer == PHP in Templates / Complex Templates
I have figured it out. I just created my own php file included all of the code and set it to the variable. for example

I made an file example.php.

in global.php i included example.php

In example.php i set the variable $ example = to all of my php code.

In the template I just put {$ example}

Thanks
(2012-04-04, 01:07 AM)soccer58us Wrote: [ -> ]I have figured it out. I just created my own php file included all of the code and set it to the variable. for example

I made an file example.php.

in global.php i included example.php

In example.php i set the variable $ example = to all of my php code.

In the template I just put {$ example}

Thanks

That's not the best method. You don't need to edit a core file like global.php.

What you do is use the MyBB plugin system and HOOK into global_start or global_end depending on what you're doing.

If you start editing core files you will have a more difficult time keeping track when it's time to upgrade.

1/2 the beauty of MyBB is the plugin system.
(2012-04-04, 02:03 AM)labrocca Wrote: [ -> ]...
1/2 the beauty of MyBB is the plugin system.

And it is a great one. Smile