Advertisement:

Author Topic: How To Create Custom Pages + Tabs [2.0 RC3]  (Read 28027 times)

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
How To Create Custom Pages + Tabs [2.0 RC3]
« on: September 28, 2010, 11:37:45 AM »
Step 1

We're going to start by creating the actions needed to get our custom page.  If you try to go to it, you'll obviously get errors as we've not yet created it.

./index.php

Find
Code: [Select]
        'movetopic2' => array('MoveTopic.php', 'MoveTopic2'),
Add After
Code: [Select]
        'mypage' => array('MyPage.php', 'MyPage'),
What this does, is when the action "mypage" is called on, it will point to ./Sources/MyPage.php and inside that, the function MyPage().

Step 2

Now, to access that page easily, we're going to create a tab to direct us there.

./Sources/Subs.php

Find
Code: [Select]
            'home' => array(
                'title' => 'Home',
                'href' => $scripturl,
                'show' => true,
                'sub_buttons' => array(
                ),
            ),

Add After
Code: [Select]
            'mypage' => array(
                'title' => 'What The Tab Says',
                'href' => $scripturl . '?action=mypage',
                'show' => true,
                'sub_buttons' => array(
                ),
            ),

This is going to add the tab we need to be able to click.  Remember to change the title.

Find
Code: [Select]
    if (isset($context['menu_buttons'][$context['current_action']]))
        $current_action = $context['current_action'];

Add After
Code: [Select]
    elseif ($context['current_action'] == 'mypage')
        $current_action = 'mypage';

Basically if you're using the action "mypage", set your current action to "mypage".  This will cause the tab to be highlighted while you're using the page.

Step 3

Now it's time to create our custom page.  Here's a basic template I use.  Remember, this doesn't exist yet!

./Sources/MyPage.php
Code: [Select]
<?php

if (!defined('SMF'))
die(
'Hacking attempt...');

function 
MyPage() {
    global 
$context;
    
$context['page_title'] = 'My Page Title Goes Here';

    function 
template_main() {
        echo 
'<center><b>Content goes here.  Remember to echo all HTML as this is in PHP.</b></center>';
    }
    
}

?>


Once you do this, you should be able to see your custom page by going to http://yoursite.com/index.php?action=mypage

If I've missed anything, let me know and I'll add it.  Also, a thanks to Cicka (I think that's how you spell it) for helping me learn a while ago, what all needs to be done.

If you have any questions, feel free to ask in a reply here.
« Last Edit: December 08, 2010, 08:02:46 PM by IceXaos »

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: How To Create Custom Pages [2.0 RC3]
« Reply #1 on: September 28, 2010, 11:44:46 AM »
In that custom page you do need to set a value for $context['current_action'] for the button to be active.

Or else you can change:

Code: [Select]
    elseif ($context['current_action'] == 'mypage')
        $current_action = 'mypage';

to:

Code: [Select]
    elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'mypage')
        $current_action = 'mypage';

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages [2.0 RC3]
« Reply #2 on: September 28, 2010, 11:47:50 AM »
In that custom page you do need to set a value for $context['current_action'] for the button to be active.

Or else you can change:

Code: [Select]
    elseif ($context['current_action'] == 'mypage')
        $current_action = 'mypage';

to:

Code: [Select]
    elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'mypage')
        $current_action = 'mypage';
You don't need to, as I'm pretty sure that's set by _GET variables.  I've never really checked, but it works like that for every page I've added.

Offline Alex' Manson

  • Full Member
  • ***
  • Posts: 506
  • Gender: Male
  • dead and gone!
    • Sisko Hosting - FREE|PAID Hosting
Re: How To Create Custom Pages [2.0 RC3]
« Reply #3 on: September 28, 2010, 11:50:42 AM »
lets say my page is called "SiskoPlanet"
so this:
Code: [Select]
  'mypage' => array(
                'title' => 'What The Tab Says',
                'href' => $scripturl . '?action=mypage',
                'show' => true,
                'sub_buttons' => array(
                ),
            ),
Will Be:
Code: [Select]
'SiskoPlanet' => array(
                'title' => 'SiskoPlanet',
                'href' => $scripturl . '?action=SiskoPlanet',
                'show' => true,
                'sub_buttons' => array(
                ),
            ),
and
Code: [Select]
  elseif ($context['current_action'] == 'mypage')
        $current_action = 'mypage';
will be:
Code: [Select]
  elseif ($context['current_action'] == 'SiskoPlanet')
        $current_action = 'SiskoPlanet';
???

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages [2.0 RC3]
« Reply #4 on: September 28, 2010, 11:51:51 AM »
If you want the action to be called SiskoPlanet, then you'll need to change that in every location the action is stated.

Offline zamg0d1

  • Semi-Newbie
  • *
  • Posts: 86
  • Gender: Male
    • Headbang.nl
Re: How To Create Custom Pages [2.0 RC3]
« Reply #5 on: September 28, 2010, 12:02:23 PM »
Ah, I will try with this one, but how to add sub-actions?

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages [2.0 RC3]
« Reply #6 on: September 28, 2010, 12:03:51 PM »
For a sub-action, which I assume you're talking about active tabs.

Code: [Select]
    elseif ($context['current_action'] == 'mysubpage')
        $current_action = 'mypage';

This will activate "mypage" tab if you're on "mysubpage".

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: How To Create Custom Pages [2.0 RC3]
« Reply #7 on: September 28, 2010, 12:15:55 PM »
Quote
You don't need to, as I'm pretty sure that's set by _GET variables.  I've never really checked, but it works like that for every page I've added.

Yes, you are correct on that. That's something new for 2.0 I wasn't aware of.

But it will only work if that page is in accessed using $_GET['action']. For other pages $context['current_action'] does need to be set.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #8 on: September 28, 2010, 12:19:33 PM »
Quote
You don't need to, as I'm pretty sure that's set by _GET variables.  I've never really checked, but it works like that for every page I've added.

Yes, you are correct on that. That's something new for 2.0 I wasn't aware of.

But it will only work if that page is in accessed using $_GET['action']. For other pages $context['current_action'] does need to be set.
Yep, but adding it like this, you're kind'a forced to use actions to get to it, plus with a tab, it's just a click away.

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #9 on: September 28, 2010, 12:28:07 PM »
Yes, but people do also add the menu bar to the home page of their site. Or to other pages where SSI.php is included and which are not accessed using the action array.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #10 on: September 28, 2010, 12:31:08 PM »
Yes, but people do also add the menu bar to the home page of their site. Or to other pages where SSI.php is included and which are not accessed using the action array.
True.  I was just attempting to cover the main idea here.  With this, they're capable of creating pages integrated with the forum, which you access by actions, as well as using PHP along with HTML.  I couldn't possibly cover every thing a user may do.

Offline zamg0d1

  • Semi-Newbie
  • *
  • Posts: 86
  • Gender: Male
    • Headbang.nl
Re: How To Create Custom Pages [2.0 RC3]
« Reply #11 on: September 28, 2010, 03:19:19 PM »
For a sub-action, which I assume you're talking about active tabs.

Code: [Select]
    elseif ($context['current_action'] == 'mysubpage')
        $current_action = 'mypage';

This will activate "mypage" tab if you're on "mysubpage".
No more like 'forum/index.php?action=admin;area=featuresettings', so in the Admin action there's a new action, that's what I ment.

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #12 on: September 28, 2010, 03:32:15 PM »
For a sub-action, which I assume you're talking about active tabs.

Code: [Select]
    elseif ($context['current_action'] == 'mysubpage')
        $current_action = 'mypage';

This will activate "mypage" tab if you're on "mysubpage".
No more like 'forum/index.php?action=admin;area=featuresettings', so in the Admin action there's a new action, that's what I ment.
if ($_GET['area'] == 'featuresettings') { do this }

Offline zamg0d1

  • Semi-Newbie
  • *
  • Posts: 86
  • Gender: Male
    • Headbang.nl
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #13 on: September 28, 2010, 03:56:50 PM »
For a sub-action, which I assume you're talking about active tabs.

Code: [Select]
    elseif ($context['current_action'] == 'mysubpage')
        $current_action = 'mypage';

This will activate "mypage" tab if you're on "mysubpage".
No more like 'forum/index.php?action=admin;area=featuresettings', so in the Admin action there's a new action, that's what I ment.
if ($_GET['area'] == 'featuresettings') { do this }
Ah you mean like this:
Code: [Select]
<?php

if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Newspost() {
    global 
$context;
    
$context['page_title'] = 'My Page Title Goes Here';

    function 
template_main() {
         
$able = array('1''2''help''verzonden''none'); // pages allowed
         
$id 'none'// standard page
         
if(!empty($_GET['id']) && in_array($_GET['id'], $able)) {
            
// allowed so we load that page
            
$id $_GET['id'];
         }
         
        if (
$_GET['id'] == 'help') {         include_once("mh.gaming-freak.nl/news/news/help.php$id.php"); }
    }
    
}

?>

But with this url it won't work :( http://mh.gaming-freak.nl/forum/index.php?action=newspost;id=help



(I'm PHP noob but trying to make it work :O)

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #14 on: September 28, 2010, 04:07:02 PM »
Why do it twice?  You're going to to check with an if statement to do certain actions anyways, so you may as well just throw it in to the main statement.

if ($_GET['id'] == '1') {
   
1();
} elseif (
$_GET['id'] == '2') {
   
2();
}

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #15 on: September 28, 2010, 04:08:45 PM »
Sorry, just actually looked at it.  What's the point of all this?

         $able = array('1''2''help''verzonden''none'); // pages allowed
         
$id 'none'// standard page
         
if(!empty($_GET['id']) && in_array($_GET['id'], $able)) {
            
// allowed so we load that page
            
$id $_GET['id'];
         }


You check again anyways, which is gonna make it completely pointless.

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #16 on: September 28, 2010, 04:15:50 PM »
No offence IX, I prefer using a mod to do this. I am little bit dizzy with codes lately. I haven't got time to finish my latest mods too.

Offline IceXaos

  • Full Member
  • ***
  • Posts: 673
    • Runedev
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #17 on: September 28, 2010, 04:24:01 PM »
No offence IX, I prefer using a mod to do this. I am little bit dizzy with codes lately. I haven't got time to finish my latest mods too.
Most MOD's only allow you to add a certain amount of pages, and it's not always a lot.  I believe there is one that allows up to 6, but that's as high as it goes AFAIK.  Anyways, this was made to help out someone with tab problems, but since he didn't have his pages set up within the forums, I figured I'd make a quick tutorial and show how.  He wanted to add PHP to custom pages, and I'm not sure if any MOD's allow that, but he didn't seem to have any luck with it.  I've never really tried custom page MOD's myself, since I don't see the point for something so quick.

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: How To Create Custom Pages + Tabs [2.0 RC3]
« Reply #18 on: September 28, 2010, 04:44:24 PM »
I agree on that. Most mods that create page don't create tab for the created page. Normally, we have to do it manually. And some of them do have limitations. There is a nice mod from arantorsmod site that can easily create tab menu. I would recommend that mod (or any mods from Arantor - well, they call him The Captain). Personally, I used cms mod (no longer available from SMF mod site. I will change to Arantor's mod later) for managing my main menu and SP for creating page.

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,887
  • Gender: Male
  • Sapienti satis.
My Mods

Sugested that too. Hey ho. I'd link you to the original discussion but it's not visible to most people (seekrit team board stuff that is more dangerous than wikileaks).


Don't PM me for support! Use the appropriate support board!