Advertisement:
2by2host

Author Topic: Adding buttons problem  (Read 1486 times)

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Adding buttons problem
« on: September 17, 2012, 09:32:30 AM »
Hello,

Im custimising a theme. The index.template.php file for the special theme.

I've added some buttons, working good.

Example:
Code: [Select]
echo '
                <li ' , $current_action=='forum' ? ' class="chosen"' : '' , '><a href="', $scripturl, '?action=forum">Forum<span>Forumet</span></a>';

But now i want to add a page, not a action. How do i do that. I'm kinda noob so xD

I we're trying like:
Code: [Select]
echo '
                <li ' , $current_page=='forum' ? ' class="chosen"' : '' , '><a href="', $scripturl, '?page=forum">Forum<span>Forumet</span></a>';

As you can se i replaced action with page. Can't get it to work, and no, im not trying to link to forum, im trying to link to a special map in my www directory.

Example:

mywebsite.com/directory

I'm trying to link it to the directory

Thanks!
/Molo

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #1 on: September 17, 2012, 09:49:53 AM »
Hi, what version SMF is that for? It looks like a 1.x theme. ???

Have you created that page yet? If so and it's outside of the SMF directory, remove the $scripturl variable and hard code in the full link.

Code: [Select]
echo '
                <li ' , $current_page=='directory' ? ' class="chosen"' : '' , '><a href="http://mywebsite.com/directory"><span>Directory</span></a>';

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #2 on: September 17, 2012, 09:54:10 AM »
Thanks!

The code works good :)

Im using 2.0.2, latest. Didn't complain when i installed the theme so i guess it's good.

But, new problem, i want it to open in the same window like the forum do etc :)

Thanks for helping me :)
/Molo

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #3 on: September 17, 2012, 10:05:48 AM »
For 2.x, the menu is now an array in Subs.php and that's what's typically used the show the menu on most themes now. But whatever works. :)

For that add target="_blank"

Code: [Select]
echo '
                <li ' , $current_page=='directory' ? ' class="chosen"' : '' , '><a href="http://mywebsite.com/directory" target="_blank"><span>Directory</span></a>';

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #4 on: September 17, 2012, 10:19:42 AM »
That didnt seem to work, still opening in a new tab :/

I'm not sure but i think it has something with
Code: [Select]
<iframe src to do.

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #5 on: September 17, 2012, 11:07:50 AM »
It could be but I don't have any experience in that area to answer correctly.

But normally, target="_blank" should open a link in a new window. ???

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #6 on: September 17, 2012, 11:18:14 AM »
No, i don't want it in a new window, i want it to in the same tab, same window, but like Forum do, like Home do.

Same window, but like minimized in the middle, idk if you understand :/

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #7 on: September 17, 2012, 11:52:14 AM »
Sorry, missread. This page contains the options. See which one works.

http://www.w3schools.com/TAgs/att_a_target.asp

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #8 on: September 17, 2012, 12:39:22 PM »
I got i working, idk how really, did something with Dreamportal.

But now I want to make the button marked when it's pressed, like the others.
This one is working: It's a action, as normal with SMF.

Code: [Select]
    if (in_array($context['current_action'], array('moderate', 'admin')))
$current_action = 'moderate';

But, my new one, is a page, how to i make it work? :/

Code: [Select]
    if (in_array($context['current_page'], array('bans')))
$current_page = 'bans';

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #9 on: September 17, 2012, 12:57:38 PM »
In what I first posted it was checking $current_page to mark that tab as active.

So if that's the case, this should work. (change the "xxx" to the name of that page)

Code: [Select]
if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'xxx')
$current_page = 'directory';

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #10 on: September 17, 2012, 01:09:26 PM »
Hello

If my page is mywebsite.com/index.php?page=bans

Then i should replace xxx with bans?

Like this?

Code: [Select]
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'bans')
$current_page = 'directory';

If so, it doesn't work :/

Managed to get it working, but it also marks the Home page, any fix?
« Last Edit: September 17, 2012, 01:27:27 PM by Molo153 »

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #11 on: September 17, 2012, 01:47:12 PM »
What did you do to get it working?

For each link, the "$current_page==" value needs to be unique.

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #12 on: September 17, 2012, 01:51:14 PM »
Code: [Select]
            echo '
                <li ' , $current_page=='walla' ? ' class="chosen"' : '' , '><a href="http://193.11.112.174/index.php?page=bans" target="">Bans<span>Server bans</span></a>';

That's the button

Code: [Select]
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'bans')
$current_page = 'walla';

That's the marking stuff, that makes the button marked. In the beginning i didn't se same $current_page, my bad.

But it's still marking both Home and Bans, i only wan't Bans marked.

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #13 on: September 17, 2012, 02:08:53 PM »
The "Home" button. Is that using $current_page or $current_action. It should be the same for all tabs.

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #14 on: September 17, 2012, 02:11:24 PM »
The "Home" button. Is that using $current_page or $current_action. It should be the same for all tabs.

$current_action = 'home';

That's the home button mark thing.

If I remove that the home button never get's marked. But, i want it marked if it's pressed xD

Code: [Select]
echo '
<li ' , $current_action=='home' ? ' class="chosen"' : '' , '><a href="', $scripturl, '">Hem<span>Förstasidan</span></a>';
               

That's the homebutton button.

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #15 on: September 17, 2012, 02:21:19 PM »
That's the problem. The home button is checking for $current_action while your button is checking for $current_page.

In the code for your button and the check, change $current_page to $current_action.

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

Offline Molo153

  • Semi-Newbie
  • *
  • Posts: 12
Re: Adding buttons problem
« Reply #16 on: September 17, 2012, 02:31:33 PM »
It's working!

Thank you so much! :)

To others:

My button, the one you press:

Code: [Select]
            echo '
                <li ' , $current_action=='walla' ? ' class="chosen"' : '' , '><a href="http://mywebsite.com/index.php?page=bans" target="">Bans<span>Server bans</span></a>';
               

And the one that marks the button:

Code: [Select]
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'bans')
$current_action = 'walla';

Once again, Thanks!
/Molo

Offline Kays

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,677
  • Gender: Male
    • Kayssplace
Re: Adding buttons problem
« Reply #17 on: September 17, 2012, 04:23:35 PM »
Great. :)

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