I want to use a bit of PHP from the internet_services theme in my own custom theme so I contacted the maintainer but never got a response, can someone tell me how I can implement this bit of code into my own theme? http://drupal.org/node/182009

Comments

vm’s picture

I believe, the code below would go into your template.php file

<?php
function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('search-theme-form', array('form' => $form));
}

function internet_services_primary($items = array()) {
  $menu = menu_get_item(variable_get('menu_primary_menu', 0));
  $output = '<div class="title">' . $menu['title'] . '</div>';
  $output .= theme('links', $items);
  return $output;
}

however, in the above you would have to change

function internet_services_primary

to:

function YOURTHEME_primary

where YOURTHEME is the name of your theme

----------------------------------------------------------------------------------------------------

The code below would go into it's own search-theme-form.tpl.php

<?php
  global $user;

  if (!$user->uid) {
    $message .= '<div>' . t('Please <a href="@login">Login</a> or <a href="@register">Register</a>', array('@login' => url('user/login'), '@register' => url('user/register'))) . '</div>';
    $message .= '<div>' . t('<a href="@password">Request New Password</a>', array('@password' => url('user/password'))) . '</div>';
  } 
  else {
    $message .= '<div>' . t('Welcome @user', array('@user' => $user->name)) . '</div>';
    $message .= '<div>' . t('<a href="@view">View</a> | <a href="@edit">Edit</a> | <a href="@logout">Logout</a>', array('@view' => url('user/' . $user->uid), '@edit' => url('user/' . $user->uid . '/edit'), '@logout' => url('logout'))) . '</div>';
  }
?>

<div class="welcome"><?php print $message ?></div>
<div class="search-form">
  <div class="title"><?php print t('Search the Site:') ?></div>
  <?php print drupal_render($form['search_theme_form_keys']) ?>
  <?php print drupal_render($form['submit']) ?>
  <?php print drupal_render($form) ?>
  <div class="advanced"><?php print l(t('Advanced'), 'search') ?></div>
</div>

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

underpressure’s picture

I understand the php template part, well i know it goes there, its the other part that I have an issue with. I want to add that part to my node.tpl

this part exactly:

  global $user;

  if (!$user->uid) {
    $message .= '<div>' . t('Please <a href="@login">Login</a> or <a href="@register">Register</a>', array('@login' => url('user/login'), '@register' => url('user/register'))) . '</div>';
    $message .= '<div>' . t('<a href="@password">Request New Password</a>', array('@password' => url('user/password'))) . '</div>';
  }
  else {
    $message .= '<div>' . t('Welcome @user', array('@user' => $user->name)) . '</div>';
    $message .= '<div>' . t('<a href="@view">View</a> | <a href="@edit">Edit</a> | <a href="@logout">Logout</a>', array('@view' => url('user/' . $user->uid), '@edit' => url('user/' . $user->uid . '/edit'), '@logout' => url('logout'))) . '</div>';
  }

When I add it nothing happens.
----------------------------
Metal head for life \m/

vm’s picture

I just went through the process of installing this theme to see what it does in reference to the theme it's being pulled from and I don't see it there either. Do you ?

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

underpressure’s picture

it's to the right of the search bar and it says welcome user and has a few useful links to user account.
----------------------------
Metal head for life \m/

vm’s picture

ahhhhhh! i had the search box disabled in my theme. I see now what it does.

Being at work I can't manipulate code. if someone else doesn't come along to help out, I'll look at it again when I get home from work.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

underpressure’s picture

anyone care to take a stab at it?
----------------------------
Metal head for life \m/

vm’s picture

Seems to work perfectly well for me.

add to template.php

function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('search-theme-form', array('form' => $form));
}

then copy the search-theme-form.tpl.php from internet services theme to your theme.

it then becomes dependant on where you call <?php print $search_box; ?> in your page.tpl.php

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

underpressure’s picture

OK, how can I make it independent of search box?

What I want is a php snippet I can inject into my page.tpl that displays links such as: Log in | Register| Forgot Password and if the user is logged in they see links relating to there account such as their profile. The above code does that but I want the extra code that relies on search stripped out, any help?

edit:
I just looked over the original post and long story short I just want to be able to stick the following code where i want in my template and work.

<?php
  global $user;

  if (!$user->uid) {
    $message .= '<div>' . t('Please <a href="@login">Login</a> or <a href="@register">Register</a>', array('@login' => url('user/login'), '@register' => url('user/register'))) . '</div>';
    $message .= '<div>' . t('<a href="@password">Request New Password</a>', array('@password' => url('user/password'))) . '</div>';
  }
  else {
    $message .= '<div>' . t('Welcome @user', array('@user' => $user->name)) . '</div>';
    $message .= '<div>' . t('<a href="@view">View</a> | <a href="@edit">Edit</a> | <a href="@logout">Logout</a>', array('@view' => url('user/' . $user->uid), '@edit' => url('user/' . $user->uid . '/edit'), '@logout' => url('logout'))) . '</div>';
  }
?>

----------------------------
Metal head for life \m/

vm’s picture

<?php
global $user;

  if (!$user->uid) {
    $message .= '<div>' . t('Please <a href="@login">Login</a> or <a href="@register">Register</a>', array('@login' => url('user/login'), '@register' => url('user/register'))) . '</div>';
    $message .= '<div>' . t('<a href="@password">Request New Password</a>', array('@password' => url('user/password'))) . '</div>';
  }
  else {
    $message .= '<div>' . t('Welcome @user', array('@user' => $user->name)) . '</div>';
    $message .= '<div>' . t('<a href="@view">View</a> | <a href="@edit">Edit</a> | <a href="@logout">Logout</a>', array('@view' => url('user/' . $user->uid), '@edit' => url('user/' . $user->uid . '/edit'), '@logout' => url('logout'))) . '</div>';
  }
?>

<div class="welcome"><?php print $message ?></div>

The above is what you want to add to a tpl.php file where you want this to work.
Notice the <div class="welcome"><?php print $message ?></div> in the above code snippet.
This a necessary component to insure that the $message is actually printed in the theme tpl.php

see example here: dev.verymisunderstood.com being used in a block.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

underpressure’s picture

This method works, thank you, I'm very grateful for your time and effort spent helping me.

Now on to theming.
----------------------------
Metal head for life \m/