Post Order - Sorting Posts by something else

13 views
Skip to first unread message

ideamenDave

unread,
Dec 18, 2009, 3:24:50 AM12/18/09
to habari-users
Hello! I've been using Habari for a couple months now, and I like
it. So far I've been able to get it to do nearly everything I needed
it to do right off the bat (despite my general ignorance of PHP), but
there's a couple few things I need that I'd like to learn about.
I've created a custom post type using the '<a href="http://
www.habariproject.org/dist/plugins/eventscontent/"
title="eventscontent plugin" target="_blank">eventscontent</a>' plugin
as a base (of course I modded it a bit to add some extra fields).
Basically it's a 'Shows' category, I'm using it as a sort of calendar
of events for my band. What I need is for these posts to be sorted
not by post entry date, but by the date of the event itself (one of
the new fields added to the new content type - post->info->eventdate),
and ultimately (details, details) would only display events in the
future (though it would also be nice to have them all displayable in
an archive).
I know this is 'easy'. I've done a lot of reading up before posting
this question, finding a handful of references to how simple it is to
<a href="http://groups.google.com/group/habari-dev/msg/
c5a4499d1f9aef37" title="A Post By Owen" target="_blank">do this sort
of thing</a> with Habari, but I just don't get it. I tried to add a
sort of filter to the home.php page (I'm using Michael Harris'
Connections theme as a base), but to no avail. It appears to sort,
but only gets through 5 (the limit of posts to display per page) then
displays the rest in standard order. Here's the snippet I used (boy I
hope this displays, I've never tried to post code before):
<code>
<?php if ( $request->display_entries_by_tag && $tag == 'shows' && !
$request->display_home ) { ?>
<?php $theme->display ( 'showtop' ); ?>
<?php $eventposts = Posts::get( array ('content_type' =>
'ideamen_show', 'status' => Post::status('published'), 'orderby' =>
$post->info->eventdate ) ); ?>
<?php foreach ( $eventposts as $post ) {
include( 'ideamen_show.php' ); }
?>
<?php } ?>
</code>

I know I'm going about it the wrong way trying to splatter code all
over the home page, but I'm fuzzy on how to move this sort of thing up
into the plugin (or the theme) to get it to behave correctly. There's
more that I'd like to tweak, but I don't want to ask too much in my
first post :)

My site: <a href="http://www.iloveideamen.com/"
title="iloveideamen.com" target="_blank">iloveideamen.com</a>
The content type plugin in text format: <a href="http://
www.iloveideamen.com/habaristuff/ideamenshowscontent.plugin.php.txt"
title="ideamenshowscontent.plugin.php.txt"
target="_blank">ideamenshowscontent.plugin.php.txt</a>

Thanks a whole bunch in advance,
--D.G. Solar

Michael C. Harris

unread,
Dec 20, 2009, 3:57:49 AM12/20/09
to habari...@googlegroups.com
2009/12/18 ideamenDave <dgs...@gmail.com>:

> Hello!  I've been using Habari for a couple months now, and I like
> it.  So far I've been able to get it to do nearly everything I needed
> it to do right off the bat (despite my general ignorance of PHP), but
> there's a couple few things I need that I'd like to learn about.

First, a big welcome to Habari (again!).

> I've created a custom post type using the 'eventscontent' plugin


> as a base (of course I modded it a bit to add some extra fields).
> Basically it's a 'Shows' category, I'm using it as a sort of calendar
> of events for my band.  What I need is for these posts to be sorted
> not by post entry date, but by the date of the event itself (one of
> the new fields added to the new content type - post->info->eventdate),
> and ultimately (details, details) would only display events in the
> future (though it would also be nice to have them all displayable in
> an archive).

What version of Habari are you using ? The ability to display by postinfo has
only been added to the Posts::get() API very recently, so it's not available in
0.6. See the thread that inspired the change here[1]. This will give you a hint
of how to do it in both 0.6 and 0.7.

This is the wiki page that should eventually hold your answer,
http://wiki.habariproject.org/en/Dev:Retrieving_Posts.

> I tried to add a sort of filter to the home.php page (I'm using Michael
> Harris' Connections theme as a base), but to no avail.  It appears to sort,
> but only gets through 5 (the limit of posts to display per page) then
> displays the rest in standard order.  Here's the snippet I used (boy I hope
> this displays, I've never tried to post code before):
>

> <?php if ( $request->display_entries_by_tag && $tag == 'shows' && !
> $request->display_home ) { ?>
> <?php $theme->display ( 'showtop' ); ?>
> <?php $eventposts = Posts::get( array ('content_type' =>
> 'ideamen_show', 'status' => Post::status('published'), 'orderby' =>
> $post->info->eventdate ) ); ?>
> <?php foreach ( $eventposts as $post ) {
> include( 'ideamen_show.php' ); }
> ?>
> <?php } ?>

Something like this for 0.7:

<?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' => 'eventdate',
'orderby' => 'info_eventdate_value ASC',
'nolimit' => TRUE
));


foreach ( $eventposts as $post ) {
include( 'ideamen_show.php' );
}
}
?>

Instead of that include, you could use:
$theme->content($post);

That would use your ideamen_show.php template, because it's the name of the
post's content type. See http://wiki.habariproject.org/en/IsContent for
details.

I think this is just a first step in improving what you're doing (ie, adding in
the only upcoming dates stuff), so do follow up with how you go.

[1] http://groups.google.com/group/habari-dev/browse_thread/thread/28d52f560f7193ef

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

ideamenDave

unread,
Dec 22, 2009, 12:53:53 AM12/22/09
to habari-users
Wonderful! Thanks Michael.
I took a day to wrap my head around your answer, poked around the
links (very helpful), and once I had a handle on it, I went ahead and
installed 0.7-alpha r3829 on my test site (I'm running 0.6.3 on the
official site). It works! I of course got a handful of errors for a
bit while mucking about with the code because I (cough) don't know
what I'm doing, but it behaves pretty much like I want it to.

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). This was done with:
$post->info->eventtimestamp = strtotime($form->eventdate->value);
I also had to re-save all of my posts after I added the eventtimestamp
field, to fill the voids that the pages were asking for. Ack. To
progress!

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.

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.

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).

The test site: http://www.iloveideamen.com/testCMS/habariTest/
Click the "Upcoming Shows" link in the ideaMenu :D

Happy Holidays to all, and thanks for the help!
--D.G. Solar

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


On Dec 20, 2:57 am, "Michael C. Harris" <michael.twof...@gmail.com>
wrote:


> 2009/12/18 ideamenDave <dgs...@gmail.com>:
>
> > Hello!  I've been using Habari for a couple months now, and I like
> > it.  So far I've been able to get it to do nearly everything I needed
> > it to do right off the bat (despite my general ignorance of PHP), but
> > there's a couple few things I need that I'd like to learn about.
>
> First, a big welcome to Habari (again!).
>
> > I've created a custom post type using the 'eventscontent' plugin
> > as a base (of course I modded it a bit to add some extra fields).
> > Basically it's a 'Shows' category, I'm using it as a sort of calendar
> > of events for my band.  What I need is for these posts to be sorted
> > not by post entry date, but by the date of the event itself (one of
> > the new fields added to the new content type - post->info->eventdate),
> > and ultimately (details, details) would only display events in the
> > future (though it would also be nice to have them all displayable in
> > an archive).
>
> What version of Habari are you using ? The ability to display by postinfo has
> only been added to the Posts::get() API very recently, so it's not available in
> 0.6. See the thread that inspired the change here[1]. This will give you a hint
> of how to do it in both 0.6 and 0.7.
>

> This is the wiki page that should eventually hold your answer,http://wiki.habariproject.org/en/Dev:Retrieving_Posts.

> [1]http://groups.google.com/group/habari-dev/browse_thread/thread/28d52f...

Michael C. Harris

unread,
Dec 23, 2009, 7:54:51 PM12/23/09
to habari...@googlegroups.com
2009/12/22 ideamenDave <dgs...@gmail.com>:
>
> ... 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

--

ideamenDave

unread,
Jan 4, 2010, 9:07:59 PM1/4/10
to habari-users
Hello again, and superThanks for the info, I believe you're getting at
the crux of what it is that I just don't get about PHP/Habari, and now
I'm as lost as ever :P
I was pretty sure that I ought to get the sorting done at a level
higher then the home.php file, but I'm missing some basic
understanding of how it all works together.

> 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 like this idea and have yet to try it, but it will surely be nicer
on the workload then having to re-save all of the show posts on the
official site (there are quite a few on the official site, and we've
got a 3 week tour coming up that I have yet to add to the calendar -
perhaps we'll be playing in a town near you!).

> 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.

Yep. Basically just added a few fields to a pre-existing content type
plugin:

public function action_form_publish($form, $post, $context)
{
// only edit the form if it's an ideamen_show
if ($form->content_type->value == Post::type('ideamen_show')) {

// add eventdate text field
$form->insert('tags', 'text', 'eventdate', 'null:null', _t
('Event Date'), 'admincontrol_textArea');
$form->eventdate->value = $post->info->eventdate;
$form->eventdate->template = 'admincontrol_text';

// add venue text field
$form->insert('tags', 'text', 'venue', 'null:null', _t('Venue'),
'admincontrol_textArea');
$form->venue->value = $post->info->venue;
$form->venue->template = 'admincontrol_text';

// add adress text field
$form->insert('tags', 'text', 'address', 'null:null', _t('Venue
Address'), 'admincontrol_textArea');
$form->address->value = $post->info->address;
$form->address->template = 'admincontrol_text';

// add with text field
$form->insert('tags', 'text', 'with', 'null:null', _t('With'),
'admincontrol_textArea');
$form->with->value = $post->info->with;
$form->with->template = 'admincontrol_text';

}
}

But I just can't wrap my head around the important bit:


> 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.

I have no frame in my head to grasp the concept of "the url you want",
and I believe I've got some studying to do to make this make sense. I
also have been looking at documentation on the rewrite rules from the
sidelines and not touching them with a 10 foot pole for fear of
puncturing them and getting PHP goo all over myself. I simply don't
understand what a rewrite rule is.

Long story short, I don't know where to put the code you posted. I
combed through it to make sure there weren't any semantic errors (I
wouldn't know if it was syntactically correct) and dropped it into my
plugin file. I then replaced the previously working snippet of code
in the home.php file with:


<?php
if ( $request->display_entries_by_tag && $tag == 'shows' &&
!$request->display_home ) {

foreach ( $shows as $post ) {
$theme->content($post);
}
}
?>
Deactivated and reactivated the plugin (I'm pretty sure that's
recommended when making changes).
Didn't work. I forgot to copy the error message, but I believe it was
the same as my next attempt. Ripped it out of the plugin file and
plopped it into the theme.php file. Getting:
--Notice: Undefined variable: shows in user/themes/ideaTheme/home.php
line 13
--Warning: Invalid argument supplied for foreach() in user/themes/
ideaTheme/home.php line 13

Where line 13 is the
foreach ( $shows as $post ) {

I then opened the rewriterules.php file and stared at it blankly for a
while :)
That was as far as I took it. I'm betting that your code is fine, and
my problem is that I just don't know how to use it properly. One of
my main hurdles in this area is that I'm still using the tag to get to
the shows 'page'. My link to Shows in the menu reads:
<a href="<?php Site::out_url( 'habari' ); ?>/tag/shows"> <?php _e
('Upcoming Shows'); ?></a>

I think what I should be using is a link that will take you to a page
that displays only posts of the ideamen_shows content type, but I have
no idea how to create such a link. This must be related to the "when
someone visits the URL for your rewrite rule" statement that is
throwing me for a loop.

Thanks again for the help, and I hope that solving this will help
others understand how this stuff works!
--D.G. Solar


On Dec 23 2009, 6:54 pm, "Michael C. Harris"

> [2]http://wiki.habariproject.org/en/Dev:Retrieving_Posts#Ordering_by_pos...
>
> --

Michael C. Harris

unread,
Jan 4, 2010, 10:58:37 PM1/4/10
to habari...@googlegroups.com
2010/1/5 ideamenDave <dgs...@gmail.com>:

> On Dec 23 2009, 6:54 pm, "Michael C. Harris" <michael.twof...@gmail.com> wrote:
> Hello again, and superThanks for the info, I believe you're getting at
> the crux of what it is that I just don't get about PHP/Habari, and now
> I'm as lost as ever :P

Ooops, sorry :)

>> 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 like this idea and have yet to try it, but it will surely be nicer
> on the workload then having to re-save all of the show posts on the
> official site (there are quite a few on the official site, and we've
> got a 3 week tour coming up that I have yet to add to the calendar -
> perhaps we'll be playing in a town near you!).
>
>> 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.
>
> Yep.  Basically just added a few fields to a pre-existing content type
> plugin:

[snip code that looks fine]

> But I just can't wrap my head around the important bit:
>> 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.
>
> I have no frame in my head to grasp the concept of "the url you want",
> and I believe I've got some studying to do to make this make sense.  I
> also have been looking at documentation on the rewrite rules from the
> sidelines and not touching them with a 10 foot pole for fear of
> puncturing them and getting PHP goo all over myself.  I simply don't
> understand what a rewrite rule is.

Habari's rewrite rules map requests to URLs, such as
http://www.iloveideamen.com/user/login, to code in Habari (or a plugin) to deal
with the request.

(As an aside, these shouldn't be confused with the web server's rewrite rules,
which basically funnel everything that isn't an existing file or directory to
Habari's index.php.)

The first function I posted, filter_rewrite_rules(), takes the existing rewrite
rules and adds a new one called 'display_shows'. This says if the requested URL
matches the regular expression pattern in parse_regex, send execution off to
the UserThemeHandler with the action 'display_shows'.

The second function, filter_theme_act_display_shows(), filters requests made to
that action. Commented this time to explain what's going on.

public function filter_theme_act_display_shows( $handled, $theme )
{

// Try to use the show.multiple.php template, and if that's not available,
// use multiple.php


  $paramarray['fallback']= array(
    '{$type}.multiple',
    'multiple',
  );

// Retrieve future shows.


  $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
  ));

// Add the shows to the theme. Access this in your template with $shows.
  $theme->shows = $shows;

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

}

> Long story short, I don't know where to put the code you posted.


> I combed through it to make sure there weren't any semantic errors (I
> wouldn't know if it was syntactically correct) and dropped it into my plugin
> file.

Sorry I didn't make that clear. Yes, it belongs in your plugin file.

> I then replaced the previously working snippet of code in the home.php
> file with:
>        <?php
>        if ( $request->display_entries_by_tag && $tag == 'shows' &&
>        !$request->display_home ) {
>                foreach ( $shows as $post ) {
>                        $theme->content($post);
>                }
>        }
>        ?>

Make a copy of home.php and call it shows.multiple.php. Then you can remove the
if statement. The page can be accessed at http://www.iloveideamen.com/shows
instead of the tag page. Now you don't have to tag shows as shows, just
making a new post of type show is enough.

Note, I still haven't tested any of this. So there might still be errors in it.
Likewise, someone else may have a better way of doing it.

> Deactivated and reactivated the plugin (I'm pretty sure that's
> recommended when making changes).
> Didn't work.  I forgot to copy the error message, but I believe it was
> the same as my next attempt.  Ripped it out of the plugin file and
> plopped it into the theme.php file.  Getting:
> --Notice: Undefined variable: shows in user/themes/ideaTheme/home.php
> line 13
> --Warning: Invalid argument supplied for foreach() in user/themes/
> ideaTheme/home.php line 13

Yep, that's because the $shows variable has only been added to the theme for
requests to http://www.iloveideamen.com/shows.

> I then opened the rewriterules.php file and stared at it blankly for a
> while :)
> That was as far as I took it.  I'm betting that your code is fine, and
> my problem is that I just don't know how to use it properly.  One of
> my main hurdles in this area is that I'm still using the tag to get to
> the shows 'page'.  My link to Shows in the menu reads:
> <a href="<?php Site::out_url( 'habari' ); ?>/tag/shows"> <?php _e
> ('Upcoming Shows'); ?></a>
>
> I think what I should be using is a link that will take you to a page
> that displays only posts of the ideamen_shows content type, but I have
> no idea how to create such a link.  This must be related to the "when
> someone visits the URL for your rewrite rule" statement that is
> throwing me for a loop.

You can construct a URL for any rewrite rule in the system with url::get() to
retrieve and url::out() to echo. So you could do this to construct the URL to
the rewrite rule created in your plugin:

<a href="<?php url::out('display_shows'); ?>"> <?php 'Upcoming Shows'; ?></a>

You don't need the _e() call, because that's only used if you're running a
translated site.

--

ideamenDave

unread,
Jan 7, 2010, 5:16:37 AM1/7/10
to habari-users
Hooboy, I think we're getting closer, despite the fact that my test
site is horribly broken now (hah!).
Before I go any farther I want to thank you for your saintly
assistance :D

> Make a copy of home.php and call it shows.multiple.php.

At first I skipped this step, but just tried it to make certain, and
no go.
What I think may be part of the trouble is I have ideamen_show.php and
ideamen_show.multiple.php files already in place - although the format
of the ideamen_show.multiple.php is likely incorrect now due to the
new method of handling the content type, it's short, so I'll post it:
<?php $theme->display( 'header' ); ?>
<!-- ideamen_show.multiple -->
<div id="content">
<p>ideamen_show.multiple called</p>
<?php
foreach ( $posts as $post ) {
include( 'ideamen_show.php' );
}
?>
<div class="navigation">
Page: <?php $theme->page_selector(); ?>
</div>
</div> <!-- #content -->
<?php $theme->display( 'sidebar' ); ?>
<!-- /entry.multiple -->
<?php $theme->display( 'footer' ); ?>

Current error messages (comes at the tippy top above the header) are:
--Notice: Undefined variable: user_filters in system/classes/theme.php
line 191
--Warning: array_intersect_key() [function.array-intersect-key]:
Argument #1 is not an array in system/classes/theme.php line 192

I'm not really sure how to describe the behavior I'm seeing on the
site, but I'll try -
http://www.iloveideamen.com/testCMS/habariTest/shows
is loading (which is wonderful!), however it's displaying all posts,
and is not using the ideamen_shows.php template at all (it's loading
entry.multiple - I added some text at the top of the templates so I
can tell which are being used). A click to page 2, and it's loading
ideamen_show.multiple - and using the ideamen_show.php template for
all posts, regardless of content type.

I get the feeling it's really close to working, and that the trouble
is right here:


> $paramarray['fallback']= array(
> '{$type}.multiple',
> 'multiple',
> );

A minute later after a brief eureka moment... Ok I'm not going to
delete all of the above but instead leave it for posterity just in
case it's useful. I just changed '{$type}.multiple' to
'ideamen_show.multiple' - and it's pulling up the correct template but
loading all posts. Another glance and another eureka - in the
ideamen_show.multiple file, changed the foreach ( $posts as $post ) to
foreach ( $shows as $post ). (This is turning into a play-by-play)
No posts load.
Tried a handful of other ways to display the content with varying
results - then looked at the plugin again.
There it is -- 'after' => strtotime('yesterday') is looking for posts
that were posted after yesterday instead of comparing with the the
eventtimestamp data. Commented it out and getting the 5 most recent
shows, properly sorted! Sweet! But... a click to page 2 and it's
the same 5 posts.

:D

I'm going to leave it there for the night. It's *really* close to
working. I'm beginning to understand how this works, and am now going
to re-read every bookmark I've got on PHP and Habari to get a grip on
the gaps that may have just been filled in. Thanks again, not only
for the help which is certainly taking considerable time and patience,
but also for the fun toy that's keeping me up 'till 4am!

--D.G. Solar


On Jan 4, 9:58 pm, "Michael C. Harris" <michael.twof...@gmail.com>

> Habari's rewrite rules map requests to URLs, such ashttp://www.iloveideamen.com/user/login, to code in Habari (or a plugin) to deal

> if statement. The page can be accessed athttp://www.iloveideamen.com/shows


> instead of the tag page. Now you don't have to tag shows as shows, just
> making a new post of type show is enough.
>
> Note, I still haven't tested any of this. So there might still be errors in it.
> Likewise, someone else may have a better way of doing it.
>
> > Deactivated and reactivated the plugin (I'm pretty sure that's
> > recommended when making changes).
> > Didn't work.  I forgot to copy the error message, but I believe it was
> > the same as my next attempt.  Ripped it out of the plugin file and
> > plopped it into the theme.php file.  Getting:
> > --Notice: Undefined variable: shows in user/themes/ideaTheme/home.php
> > line 13
> > --Warning: Invalid argument supplied for foreach() in user/themes/
> > ideaTheme/home.php line 13
>
> Yep, that's because the $shows variable has only been added to the theme for

> requests tohttp://www.iloveideamen.com/shows.


>
> > I then opened the rewriterules.php file and stared at it blankly for a
> > while :)
> > That was as far as I took it.  I'm betting that your code is fine, and
> > my problem is that I just don't know how to use it properly.  One of
> > my main hurdles in this area is that I'm still using the tag to get to
> > the shows 'page'.  My link to Shows in the menu reads:
> > <a href="<?php Site::out_url( 'habari' ); ?>/tag/shows"> <?php _e
> > ('Upcoming Shows'); ?></a>
>
> > I think what I should be using is a link that will take you to a page
> > that displays only posts of the ideamen_shows content type, but I have
> > no idea how to create such a link.  This must be related to the "when
> > someone visits the URL for your rewrite rule" statement that is
> > throwing me for a loop.
>
> You can construct a URL for any rewrite rule in the system with url::get() to
> retrieve and url::out() to echo. So you could do this to construct the URL to
> the rewrite rule created in your plugin:
>
> <a href="<?php url::out('display_shows'); ?>"> <?php 'Upcoming Shows'; ?></a>
>
> You don't need the _e() call, because that's only used if you're running a
> translated site.
>
> --

Reply all
Reply to author
Forward
0 new messages