i'm trying to print the service links at the top of the page, underneath the title. i found this code in the example template.php file:
<?php
/**
* @file
* Example template.php for service_links.module
* Use <?php print $service_links ?> to insert links in your node.tpl.php or you page.tpl.php file.
*/
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case 'node':
case 'page':
if (module_exists('service_links')) {
$vars['service_links'] = theme('links', service_links_render($vars['node'], TRUE));
}
break;
}
return $vars;
}
i copied the function into my template's template.php file, and then added print $service_links to my node.tpl.php file. nothing. it doesn't print the service links. i can get them to show up in the links, and i can get them to show up in the node (under the content), but both of these are default options. i can't get them to print where i want them to print.
am i missing a step? do i need to change something in the function?
thanks.
Comments
Comment #1
yuriy.babenko commentedI'm not sure what's wrong with your solution, but here's another way to solve your problem:
- create a new region "content top"; this is done by modifying the theme's .info file - http://drupal.org/node/171224
- go to blocks administration and move the service links block to the content top region
- modify page.tpl.php to print the content top variable above the $content variable. For example, if you added "regions[content_top] = Content Top" to your themes regions, you would use "print $content_top;"
Comment #2
japanitrat commented_phptemplate_variables(..) is no longer supported in D6.
use preprocess_callback instead, see http://drupal.org/node/132442#theme-templates for more information
Comment #3
debonator commentedok, i'm lost. how do i use the preprocess_callback function? i'm a newbie.
this is what i have, and it's definitely not working:
Comment #4
yuriy.babenko commentedThrow this into your template.php:
This will make a variable called $service_links available to your node template files (ex. node.tpl.php).
If you want the links to only appear once at the top of the page, then you need to use phptemplate_preprocess_page() instead.
Comment #5
debonator commentedone last question: why do some examples show an underscore before phptemplate (_phptemplate) and some do not? i'm assuming the underscore is unnecessary.
thanks for your help.
Comment #6
yuriy.babenko commentedIn general, Drupal functions beginning with an underscore are "internal/helper" functions. Basically, not hooks/theme over rides, or anything like that.
I'm not 100% sure of why some phptemplate functions are also prefixed with an underscore. This may be a difference between how phptemplate is setup in Drupal 5 and in Drupal 6... If there's an example, go with what's in the example :)
Comment #7
typehost commentedThanks for the explanation. I tried this with both phptemplate_preprocess_page and phptemplate_preprocess_node but could not get it to work.
Comment #8
greenskin commentedYou will need to implement the hook_nodeapi() function in a custom module and change the weight of the Service Links to a negative number, do this in the 'view' op.
Comment #9
netentropy commentedi see how this works but what if we wanted to print each service link separately?
Comment #10
xjessie007 commentedHere is an alternative way.
There are two functions in service_links.module.
The theme_service_links_node_format() is responsible for theming the output when it is appended to the node.
The theme_service_links_block_format() function themes the content if you display it as a block.
hook_block() is where the output is passed to Drupal.
For some reason, if you enable block display, service links gets displayed at both places - appended to the node and in the sidebar block too. So, if you want to display the service links as a block but not in the sidebar but let's say at the top of the post (and you want to turn off displaying service links at the end of a node too), you need to modify these functions here a little.
Uncomment everything from inside of theme_service_links_node_format. This will stop displaying service links at the end of a node.
Because theme_service_links_block_format displays the service links as UL-LI by default which is ok for sidebar block but not very nice for a top/bottom content block, you need to modify theme_service_links_block_format. I probably did not do it the best way, but I think it was the easiest way. I used the strip_tags($a, 'div a img') function to just strip all but a, div, img HTML tags from the already themed output.
Now you just enable your block and position it to content top or whereever you like. Works fine.
Note, here are other Drupal thread related to the same or similar problem:
http://drupal.org/node/257361
http://drupal.org/node/288612
http://drupal.org/node/214939
__________________
Drupal cache clean up - cache_clear_all()
How to delete or clear Drupal cache tables?
Comment #11
green monkey commentedThank you for your post. I didn't notice there was a block avaiable - so thanks.
I'm using a Theme with content bottom, so it is very easy to apply.
However, I would like the links inline
above didn't work, is there another way?
Comment #12
fleshgrinder commentedBecause your CSS is overwritten by the system.css style, use this:
Only your service-links items will be displayed inline, it won't affect anything else.
Kindest regards
Fleshgrinder
Comment #13
SallySaucer commentedIn service_links.module @ line 204 -> function service_links_nodeapi(...
find code: '#weight' => 10 (appears 4 times)
change to -50 or whatever, as long as it's lighter that the content.
Not sure how to implement in template.php
Comment #14
vradul commentedThis will work for Drupal 5.
You'll have to work on CSS positioning yourself, but this will put service links at the top, left aligned, under the author name, as well as in the links if you want it in both places. You can disabled it in the links section if it looks too busy, and this will still display it at the top.
In your themes template.php:
Insert the following immediately after function _phptemplate_variables($hook, $vars) { to make the $service_links variable available to your node tpl files
In your themes node.tpl.php insert <?php print $service_links; ?> as shown here
Comment #15
cookiesunshinex commentedThis worked for me, but isn't my preferred option because the next time I update the module, I have to remember to make this modification.
This need to be updated in the Drupal 6 version of template.php in the servicelinks module directory. It is currently wrong.
Also, this creates two different service links bars on all my nodes. If I place this in the theme, should I disable service links for nodes in the admin panel?
Comment #16
yrre7 commentedI have trouble making it work for Drupal 6. The above code doesn't work for me at all. Is there any variable changes?
Comment #17
robbertnl commented#4 works
This makes the service_links variable available in your node.tpl.php (not in page.tpl.php)
Add in node.tpl.php
Now disable service_links for all nodetypes, else you would get the service links twice. See /admin/settings/servicelinks
As mentioned before (in #15), this should be modified in template.tpl.php of the 6.x-1.x version
Comment #18
TheCrow commentedComment #20
omahmThis can be added to page.tpl.php if people are interested in for example, adding service links to page regions without resorting to a block or custom module.
Add the following to your themename_preprocess_page() call in template.php
and then add the following to your page.tpl.php file
Comment #21
msosin commentedI have a little problem with introducint that to drupal 7.
What I get is "array" and that's it.
What do I do wrong?
Thanks for your help.
M
Comment #22
ressaPerhaps clear your cache? It works for me in Drupal 7 in template.php:
EDIT: I was getting "Notice: Undefined variable: service_links in include()..." and "Notice: Undefined index: service_links in THEMENAME_preprocess_page()..." in my log files with this solution.
I found an easier way, without using template.php, from this post http://drupal.org/node/1293474 - Thanks goes to TheCrow! Just insert this in your page.tpl.php:
Comment #23
Garabed Setrakian commentedI'm sorry you all had to go through so much trouble. I drove myself crazy with this issue for the longest time until I came across Assigning a weight in Configure> Service Links> How to display Service Links> Service LInk in nodes>
Assign a weight: -10 for above or keep at 10 for below nodes. Hope it helps.
Comment #24
twooten commentedIf you want to print the service links block in a node template then the following should work.
Comment #25
pinueve commentedCSS solution:
for widgets (FB, pinterest, linkedin) you can not change images, for General Services (twitter, G+) you can upload your own images.
Here is my CSS code.
/* services share links */`
.service-links ul li {
text-decoration: none;
display: inline;
overflow: hidden;
list-style: none;
padding-right: 10px;
vertical-align: baseline;
float: left;
}
.service-links li {
display:inline;
vertical-align: bottom;
position: relative;
}
.service-links .service-links-linkedin-share-button {
top: 5px;
}
.service-links .service-links-facebook-share {
bottom: 5px;
}