MyBB Community Forums

Full Version: Index Header
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I currently use
pre_output_page for my plugin but I would like it to only show on the index, same place but on the index only.
You can either do an if statement to check if you're on the index page, or use the find_replace_templatesets() function to edit the index template.
Okay confusing. I'd just like to let you know, this is my first ever plugin and I only know very basic php so I sort of need it broken down into smaller steps.

Like what if statement should I use?
Wrap your code inside this:

if(THIS_SCRIPT == "index.php")
{
//Example
}
Like this?
function hello_world($page)
if(THIS_SCRIPT = "index.php")
{
  global $mybb;

  $date = my_date($mybb->settings['regdateformat'], $post['regdate']);

  $page = str_replace("<div id=\"content\">", "<center><div id=\"content\"><p>Your username is {$mybb->user['username']} and you registered in {$date}. Enjoy your visit!</p></center>", $page);
  
  return $page;
} 
You're missing your function's brackets:

function hello_world($page)
{
if(THIS_SCRIPT = "index.php")
{
  global $mybb;

  $date = my_date($mybb->settings['regdateformat'], $post['regdate']);

  $page = str_replace("<div id=\"content\">", "<center><div id=\"content\"><p>Your username is {$mybb->user['username']} and you registered in {$date}. Enjoy your visit!</p></center>", $page);
  
  return $page;
}
}
Parse error: syntax error, unexpected '=' in /home/zingorwe/public_html/mybbprofessor/inc/plugins/hello.php on line 103
Oops, my bad. This should work:

function hello_world($page)
{
if(THIS_SCRIPT == "index.php")
{
  global $mybb;

  $date = my_date($mybb->settings['regdateformat'], $post['regdate']);

  $page = str_replace("<div id=\"content\">", "<center><div id=\"content\"><p>Your username is {$mybb->user['username']} and you registered in {$date}. Enjoy your visit!</p></center>", $page);
  
  return $page;
}
} 
Much better, works perfectly now, thanks.

+Rep again.