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" <[email protected]>
wrote:
> 2010/1/5 ideamenDave <[email protected]>:
>
> > On Dec 23 2009, 6:54 pm, "Michael C. Harris" <[email protected]>
> > 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
> ashttp://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 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.
>
> --
> Michael C. Harris, School of CS&IT, RMIT
> Universityhttp://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