[themes] targeting variables in my node-blog.tpl.php file
Ng Chin Kiong
ckng at fordrupal.com
Tue Apr 14 09:58:44 UTC 2009
If you want to remove blog_usernames_blog from $link, put this in
template.php
/* duplicate theme_links() and add the 3rd line (marked with HERE) */
function phptemplate_links($links, $attributes = array('class' => 'links'))
{
$output = '';
// HERE: just add this line, the rest are from theme_links()
unset($links['blog_usernames_blog']);
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out
themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] ||
($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span>
for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= /*'<span'. $span_attributes .'>'.*/ $link['title']
/*.'</span>'*/;
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
For changing $submitted, add to your template.php
function phptemplate_node_submitted($node) {
// make your changes
return t('By !username (posted on @datetime)'),
array(
'!username' => theme('username', $node),
'@datetime' => format_date($node->created),
));
}
For phptemplate_preprocess_node, if you want to introduce new variables or
modify existing one. Of course it can be used to change submitted as well,
but not $links as it has been generated.
function phptemplate_preprocess_node(&$vars, $hook) {
$author = theme('username', $vars['node']);
$date = format_date($vars['node']->created, 'medium');
$vars['submitted'] = $author . ' - ' . $date;
}
Cheers,
CK Ng
forDrupal Premium Themes (http://fordrupal.com)
- we make drupal beautiful
On Tue, Apr 14, 2009 at 1:50 PM, brendan, fresh-off.com <hello at fresh-off.com
> wrote:
> Here's as far as I was able to get using CK Ng's suggestion:
>
>
>
> function phptemplate_preprocess_node(&$vars, $hook) {
>
> //try to remove 'blog_usernames_blog' from links array
>
> $vars['links'] = unset($links[0]);
>
> }
>
>
>
>
>
> it throws this error on the template.php page:
>
> *Parse error: syntax error, unexpected T_UNSET*
>
>
>
> As I said, writing php from scratch is difficult for me. Am I even on the
> right track?
>
>
>
> Thanks for any help!
>
>
>
> Brendan
>
>
>
>
>
> *From:* themes-bounces at drupal.org [mailto:themes-bounces at drupal.org] *On
> Behalf Of *brendan, fresh-off.com
> *Sent:* Monday, April 13, 2009 6:02 PM
>
> *To:* 'A list for theme developers'
> *Subject:* Re: [themes] targeting variables in my node-blog.tpl.php file
>
>
>
> *Thanks for your responses CK Ng and J. Sint Jago!*
>
> I don’t think my PHP skills are good enough to write the necessary function
> from scratch. However, I'm usually able to modify existing examples.
>
>
>
> CK, Based on your response to Sebastian and the reading on Drupal.org, it
> seems I need to add phptemplate_preprocess_node() to template.php. But I'm
> not sure exactly how its supposed to be written.
>
>
>
> Using the Devel Mod I got the following info (or see attached screenshot):
>
>
>
> ---
>
> parents: node.tlp.php < page.tlp.php
>
> function called: theme_links()
>
> Candidates Function names: myTheme_links < phptemplate_links < theme_links
>
>
>
> Next it lists 2 arrays for the theme_links() function. Those elements
> are: links array & attributes array
>
> The links array has 3 elements, the first of which is the array I don’t
> want to display: blog_usernames_blog
>
> ----
>
>
>
>
>
> I think that’s all of the information I need, but I'm still not sure what
> to do next, or where to find an example of the code to modify and insert
> into template.php to keep it from showing blog_usernames_blog.
>
>
>
> I'm stuck, any further suggestions?
>
>
>
>
>
> *From:* themes-bounces at drupal.org [mailto:themes-bounces at drupal.org] *On
> Behalf Of *Ng Chin Kiong
> *Sent:* Friday, April 10, 2009 2:09 AM
> *To:* A list for theme developers
> *Subject:* Re: [themes] targeting variables in my node-blog.tpl.php file
>
>
>
> brendan,
>
>
>
> You can use template preprocessor. See my latest reply on "Re: how to stop
> a 'view' from showing a field?"
>
>
>
>
> Cheers,
> CK Ng
>
> forDrupal Premium Themes (http://fordrupal.com)
> - we make drupal beautiful
>
> On Fri, Apr 10, 2009 at 3:53 PM, brendan, fresh-off.com <
> hello at fresh-off.com> wrote:
>
> *Hello, *
>
> I can't seem to figure out how to effectively target two different values
> in my node-blog.tpl.php file:
>
>
>
> *$submitted*
>
> *$links*
>
>
>
> For the $submitted value, I'd like to insert some xhtml tags in there so
> that I can target them with CSS.
>
>
>
> Currently it writes the data to the page like this:
>
>
>
> ---
>
> Submitted by super_user on April 9, 2009 - 2:49pm
>
> ---
>
>
>
> But I'd like to get some xhtml tags around the *User* and the *Month*. It
> would also be nice if I could delete the hour - but that’s not as important.
>
>
>
> For the *$links* value, I'd like to figure out how to remove the *Author*.
> Currently, the $links value writes*:**"Author's Blog", "Read More...",*and
> *"Add comments"* to the teaser. How do I remove just the "Authors blog"
> info from the $links value?
>
>
>
> Unfortunately, I know enough PHP to get myself confused a lot, and I've
> been googling and searching Drupal.org all day with no luck.
>
> Hopefully the nice folks on this list can help!!
>
>
>
>
>
> *brendan, fresh-off.com*
>
> Creative Direction & Consultation: Web | Print | Brand
>
>
>
> http://fresh-off.com
>
> hello at fresh-off.com
>
> 206.328.1067
>
> seattle.usa
>
>
>
>
>
>
> _______________________________________________
> themes mailing list
> themes at drupal.org
> http://lists.drupal.org/mailman/listinfo/themes
>
>
>
> _______________________________________________
> themes mailing list
> themes at drupal.org
> http://lists.drupal.org/mailman/listinfo/themes
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.drupal.org/pipermail/themes/attachments/20090414/b257a416/attachment-0001.htm>
More information about the themes
mailing list