Formatting event block

jsimonis - March 4, 2006 - 02:52

What I'd like to do is...

Pull a list that looks like this:

Date - Event title

The date would not be linked to the event's details, but the event title would.

Right now we're manually adding the date to the beginning of every event's name. It would be nice to have it done automatically, as not everyone who posts events notices the item at the top that specifically tells how to name the event.

People aren't quite as interested in the message about how many hours/days to an event-- they've told us they would rather have the date. Then they don't have to figure out what day is 17 days from now.

I found a snippet that allows me to put the date at the end, but I would rather have it at the beginning.

Here's what ours says now

function theme_event_upcoming_item($node) {
  $output = l($node->title, "node/$node->nid", array('title' => $node->title));
  if ((event_get_types('all') + event_get_types('solo')) > 1) {
    $output .= '<span class="event-nodetype">'. t("($node->typename)") .'</span>';
  }
  $output .= '<span class="event-timeleft">('. $node->timeleft .')</span>';
  return $output;
}

Anyone know how to do this? Everything I've tried so far hasn't worked.

Hack

BoatDaddy - March 4, 2006 - 03:32

I have the Upcoming Events block displaying date instead of timeleft with the following

  $output .= '<span class="event-timeleft">'. _event_date('m-d-Y', $node->event_start) . " " . $node->tz .'</span>';

Use that line instead of the last $output line in the code above. Note: _event_date is required to properly offest timezone for your site/user. This takes care of the first step.

As for displaying the date prior to the event, move that line to the top, remove the SPAN stuff or fiddle with css to remove the line break. Make sure to change the .= and = in the $output lines.

I also commented out the entire IF statement to remove the "(event)" display becuase I don't have event categories.

Yes, its a total hack :)

I tried that, only I must

jsimonis - March 4, 2006 - 04:25

I tried that, only I must have something wrong in there (maybe a comma or something in the wrong place), as I keep getting errors. I'm still fairly new to PHP, so I wouldn't be surprised if it was something small tripping me up.

Everything worked fine when I had the date at the end, but that confused people, lots of complaints came in, etc. People want the date at the beginning.

So I've just been manually adding it to every event's title. But that makes it longer than necessary, which takes up room on the month view of the calendar.

I'm fine with even having the date have the link on it. It's just that I have seen it on Drupal/CS sites the way I'd like it to be, so I know it will work. Unfortunately, none of them want to share how they've done it.

So I was hoping maybe someone around here was already doing it, and could share, or show me how to do it.

Thanks,

--
Jenni S.

Anyone have any idea of how

jsimonis - March 4, 2006 - 23:25

Anyone have any idea of how to do this?

Thanks,

--
Jenni S.

Here is how

BoatDaddy - March 6, 2006 - 18:46

Jenni,

The following code should replace the function you listed above. I've tested it and it will do what you want.

function theme_event_upcoming_item($node) {
  // Initialize the content to nothing
  $output = "";
  // Put in the date, stripped of any tags/class to prevent putting it on a seperate line
  $output .=  _event_date('m-d', $node->event_start) . " " . $node->tz. " ";
  // Put in the event title with link
  $output .= l($node->title, "node/$node->nid", array('title' => $node->title));
  // Return the output back to Drupal for display
  return $output;
}

If you want the Year to appear in the date, change 'm-d' to 'm-d-Y' or 'm-d-y'.

Here is a link for some basic information on PHP :)
http://www.php.net/manual/en/tutorial.firstpage.php

Cheers,

Mike

Thanks!

jsimonis - March 7, 2006 - 15:05

Thanks!

--
Jenni S.

How Would I Add The Start Time of The Event?

politic - April 24, 2006 - 05:29

Mike,

How would I go about adding the start time of the event, right after the date, in the code you provided above?

Please advise.

Thanks in advance!

- Gur

What you need to do is

somes - April 30, 2006 - 22:11

What you need to do is reorder the way the node renders

$output .= '('. $node->timeleft .')';
$output = l($node->title, "node/$node->nid", array('title' => $node->title));
if ((event_get_types('all') + event_get_types('solo')) > 1) {
$output .= ''. t("($node->typename)") .'';
}
return $output;

nothing new there in that i just reordered the output - you'll need to change the $node->timeleft variable in the event.module file if you look in there theres also a varible named $node->event_start

so your new code should look like

$output .= '('. $node->event_start .')';
$output = l($node->title, "node/$node->nid", array('title' => $node->title));
if ((event_get_types('all') + event_get_types('solo')) > 1) {
$output .= ''. t("($node->typename)") .'';
}
return $output;

might work havent tested it - I will cause I'll need some functionality like this soon

just tried it but had to

somes - May 1, 2006 - 08:36

just tried it but had to add
format_date($node->event_start, 'custom', 'Y/m/d')

Changing the modules like this is not good practice, I'm guessing that that these inclusions can be added via a theming function so if any has any ideas I'd love to know

later

PHP for new block?

benedett - May 25, 2006 - 20:05

It would be great to have the PHP to generate the Events Block, so I could just paste it into a new block and customize things that way. It would also allow my superusers to customize this without giving them access to the Drupal php files.

 
 

Drupal is a registered trademark of Dries Buytaert.