2009/12/22 ideamenDave <[email protected]>:
>
> ... It works!

Fantastic!

> Here's the final snippet that does the trick in the home.php file:
> <?php
> if ( $request->display_entries_by_tag && $tag == 'shows' &&
> !$request->display_home ) {
>   $theme->display ( 'showtop' );
>   $eventposts = Posts::get(array(
>   'content_type' => Post::type('ideamen_show'),
>   'status' => Post::status('published'),
>   'has:info' => 'eventtimestamp',
>   'orderby' => 'info_eventtimestamp_value ASC',
>   'nolimit' => TRUE
>   ));
>   foreach ( $eventposts as $post ) {
>     if ( $post->info->eventtimestamp > strtotime('yesterday') ) {
>       include( 'ideamen_show.php' );
>     }
>   }
> }
> ?>
>
> Note that there is a new field 'eventtimestamp'.  I had to add another
> field into the content type plugin to convert the event date string
> into a timestamp for proper sorting (it got them mixed up sorting by
> the string value).

Depending on the format of your time, you might be able to use a database
function to force the sorting to be correct[1]. For example, as is done on [2],
you can use ABS to force a string into a number.

> I tried the "$theme->content($post);" method instead of the include,
> and it filled the page with only the latest post.  I likely
> implemented it wrong.  The include does the trick though.

$theme->content($post); will only work inside the loop. But yeah, it's probably
not something to worry about right now if it's working.

> Also note the "if ( $post->info->eventtimestamp > strtotime
> ('yesterday') )" that gets it to display only events that happened
> after yesterday.  I'm all giddy now.

That really should be done in the query, so you can eliminate that. This should
do the trick, properly integrated with the query above.

Posts::get(array('after' => strtotime('yesterday'));

I've now added that to the wiki page. (Anyone else who knows this stuff should
feel free to fill in some of the other sections!)

The first if statement bothers me a bit though. You have a custom content type,
right ? And Date, Venue etc are fields that you've added to the publish page
for that content type ? That's what I'd do. Then I'd create a rewrite rule for
the url you want, and in the action function just run that query. Then when
someone visits the URL for your rewrite rule, only those posts will be
displayed.

Untested, and others may have better ways:

public function filter_rewrite_rules( $rules )
{
  $rules[] = new RewriteRule(array(
    'name' => 'display_shows',
    'parse_regex' => '%^shows(?:/page/(?P<page>\d+))?/?$%',
    'build_str' => 'shows(/page/{$page})',
    'handler' => 'UserThemeHandler',
    'action' => 'display_shows',
    'priority' => 2,
    'rule_class' => RewriteRule::RULE_PLUGIN,
    'is_active' => 1,
    'description' => 'Display shows' )
  );
  return $rules;
}

/**
 * @todo Can't remember if paging will be handled automatically
 */
public function filter_theme_act_display_shows( $handled, $theme )
{
  $paramarray['fallback']= array(
    '{$type}.multiple',
    'multiple',
  );

  $shows = Posts::get(array(
    'content_type' => Post::type('ideamen_show'),
    'status' => Post::status('published'),
    'after' => strtotime('yesterday'),
    'has:info' => 'eventtimestamp',
    'orderby' => 'info_eventtimestamp_value ASC',
    'nolimit' => TRUE
  ));

  $theme->shows = $shows;

  $theme->act_display( $paramarray );
  return TRUE;
}

> Now I suppose I'll have to update my live version to 0.7 and go for
> the gold.  My next project is figuring out how to display custom
> headers for each user on posts (could be as simple as loading a
> different style class based on $post->author->username, but my efforts
> in that direction didn't quite work).

We'll come back to that later :)

> p.s. Are we getting a shiny new official 0.7 release for Christmas
> this year?

Sadly, no.

[1] See here for MySQL functions. Numeric or date functions may help you.
[2] http://wiki.habariproject.org/en/Dev:Retrieving_Posts#Ordering_by_post_info

-- 
Michael C. Harris, School of CS&IT, RMIT University
http://twofishcreative.com/michael/blog
IRC: michaeltwofish #habari

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/habari-users

Reply via email to