The website is for sale. Check here for more information.
This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.
Random display
#1
This is an idea I've been tossing around for my site... Since we're a multi-genre writing site, it'd be nice if there was a way for me to add various plot descriptions to the database and then have PHP code randomly pick and display one in our sidebar.
 
So I've been working on getting this plugin complete. But before I really spent a lot of time getting the admin side working, I wanted to ensure the user side was at least functioning. (Since for now I can manage this by adding/editing plots manually via SQL without needing to have the backend parts done.)
 
So I've installed Frostschutz's Hooks plugin, but for the life of me I cannot figure out how to get my code to display properly.
 
I have a feeling there's an error somewhere that I'm just not seeing. (I readily admit I'm rather new to PHP and not exactly skilled.)
 
Here's the code I'm trying to use:
 
 
Code:
// necessary to edit the templates or pull from the database
global $mybb, $templates, $db;
 
//Tells the system where to hook in and what function to call
$plugins->add_hook("pre_output_page", "rndm_plot_placement");
 
 
function rndm_plot_placement(&$page)
{
 
//sets the type of query to run on the database.
$query = $db->simple_select('rndm_plot', '*', 'disabled=0', array('order_by' => 'RAND()', 'limit' => 1));
 
// disabled=0 means this part hasn't been hidden.
 
$plot = $db->fetch_array($query);
 
if ($plot)
{
$page = str_replace('rndm_plot_chosen', $plot['theplot'], $page);
/*
'rndm_plot_chosen' is the section in templates to get replaced.
'theplot' is the actual html to get entered into the 'rndm_plot_chosen' place.
*/
 
}
else
{
// no plots visible so get rid of the code
$page = str_replace('rndm_plot_chosen', '', $page);
}
 
}
 
In the database I have a table called "mybb_rndm_plot" with 3 entries. So I know contents are there. (I've tried calling the plugin with the prefix mybb_ and without but neither way makes any difference. Though it's my understanding that without prefix should work since the $db should add that automatically as part of it's function.)
 
 
 
I'm not getting any syntax errors so I don't think that's an issue. But nothing is happening at all (it's not replacing the line in the templates it's supposed to be but it's not throwing back any error messages either) so I have no idea what's going on. 
 
Anyone see where I've made the mistakes? Or places where it's not working? Any help would be appreciated.
 
(Note - I don't have the forum placed online, it's a private development board running on my local server only. But if you needed to see it live, I could set it up on my testing board and PM the link and a set of access credentials to you.)
 
Reply



Messages In This Thread
Random display - by VirusZero - 05-18-2014, 07:22 AM
RE: Random display - by Diogo Parrinha - 05-18-2014, 10:57 AM
RE: Random display - by VirusZero - 05-18-2014, 11:55 AM
RE: Random display - by Diogo Parrinha - 05-18-2014, 10:12 PM
RE: Random display - by VirusZero - 05-19-2014, 03:46 AM
RE: Random display - by Diogo Parrinha - 05-19-2014, 08:08 PM
RE: Random display - by VirusZero - 05-20-2014, 09:40 AM
RE: Random display - by Diogo Parrinha - 05-20-2014, 09:29 PM
RE: Random display - by VirusZero - 05-21-2014, 12:20 PM
RE: Random display - by Diogo Parrinha - 05-21-2014, 09:40 PM
RE: Random display - by b.h. - 05-24-2014, 06:10 AM
RE: Random display - by Diogo Parrinha - 05-24-2014, 06:19 AM
RE: Random display - by b.h. - 05-24-2014, 08:47 PM
RE: Random display - by VirusZero - 05-27-2014, 12:10 PM
RE: Random display - by Diogo Parrinha - 05-27-2014, 09:27 PM
RE: Random display - by VirusZero - 06-03-2014, 09:28 AM
RE: Random display - by Diogo Parrinha - 06-03-2014, 09:03 PM
RE: Random display - by VirusZero - 06-04-2014, 02:19 AM
RE: Random display - by Diogo Parrinha - 06-04-2014, 02:45 AM
RE: Random display - by VirusZero - 06-04-2014, 04:09 AM
RE: Random display - by Diogo Parrinha - 06-04-2014, 06:40 AM



Users browsing this thread: 2 Guest(s)

About MyBB-Plugins

Plug Yourself into the best MyBB AddOn.

Copyright © 2009-2021 MyBB-Plugins Forums.

Statistics

  • 51,000+ Posts
  • 19,000+ Members
  • 3,600+ Threads

Impressed? For sure
Check Full Stats here