Organizing Lists
13 posts by 2 authors in: Forums > CMS Builder
Last Post: February 8, 2010 (RSS)
I am applying cms to a school district site which has a page displaying a meeting agenda. I receive these agendas weekly... and as I receive them, I upload them. There's about 2 or 3 per month... in the sidebar, I have them listed:
January 11th, 2010
January 25th, 2010
February 2nd, 2010
These are all added with the assistance of a list section in CMSB... I have the fields for month_day, year, title, content, etc... I would like to insert a break between months, automatically... so it would read:
JANUARY
January 11th, 2010
January 25th, 2010
FEBRUARY
February 2nd, 2010
And when I add one that is "MARCH" it'll display a MARCH heading, without me having to split the code into seperated filtered sections for each month. I'm guessing you might return this post with a set of "if/else" statements... but I'm curious as to what you think would do it. let me know if you can.
Creative Director
JAM Graphics
Re: [jtedescojam] Organizing Lists
By Chris - February 3, 2010
Can you please post the complete PHP source code for your page? That way I'll be able to see your section name and field names to write you up a solution.
Chris
Re: [chris] Organizing Lists
<?php foreach ($agendasRecords as $record): ?>
<p><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> <?php echo $record['month_day'] ?> <?php echo $record['year'] ?></a></p><?php endforeach ?>
here's the page that displays the results.
http://www.pequannock.org/district/board-of-education/agendas2010.php
Creative Director
JAM Graphics
Re: [jtedescojam] Organizing Lists
By Chris - February 5, 2010
So you're using two textfields (month_day and year) instead of a date field? In your above example, month_day contains "January 11th", "January 25th," and "February 2nd"?
If that's the case, you can extract the month out of your month_day field and output headers whenever the month name changes, like this:
<?php $currentMonth = ""; ?>
<?php foreach ($agendasRecords as $record): ?>
<?php $words = explode(" ", $record['month_day']); ?>
<?php $monthNameInCaps = strtoupper(@$words[0]); ?>
<?php ?>
<?php if ($monthNameInCaps != $currentMonth): ?>
<?php $currentMonth = $monthNameInCaps; ?>
<p><b><?php echo $currentMonth; ?></b></p>
<?php endif; ?>
<?php ?>
<p><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> <?php echo $record['month_day'] ?> <?php echo $record['year'] ?></a></p>
<?php endforeach; ?>
I hope this helps! Please let me know if you have any questions.
Chris
Re: [chris] Organizing Lists
here's the result: http://www.pequannock.org/district/board-of-education/agendas20102.php
Would you be able to write in next to each line what they mean? I'd like to try to decipher it so I can use it in other contexts, but i don't understand $currenMonth, $words, explode, etc... I see there's some extra code in there because I included the 'day' in the month_day field.. so I'm not sure how I could use this in order contexts.
thanks again.
Creative Director
JAM Graphics
Re: [jtedescojam] Organizing Lists
By Chris - February 5, 2010
You can do this with a date field by supplying a "where" clause like: "YEAR(date) = 2010". Or, if you want the year supplied by the visitor: "YEAR(date) = '".mysql_escape($_REQUEST['year'])."'".
Here are some line numbers for reference:
[01] <?php $currentMonth = ""; ?>
[02] <?php foreach ($agendasRecords as $record): ?>
[03]
[04] <?php $words = explode(" ", $record['month_day']); ?>
[05] <?php $monthNameInCaps = strtoupper(@$words[0]); ?>
[06] <?php ?>
[07] <?php if ($monthNameInCaps != $currentMonth): ?>
[08] <?php $currentMonth = $monthNameInCaps; ?>
[09] <p><b><?php echo $currentMonth; ?></b></p>
[10] <?php endif; ?>
[11]
[12] <?php ?>
[13] <p><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> <?php echo $record['month_day'] ?> <?php echo $record['year'] ?></a></p>
[14]
[15] <?php endforeach; ?>
[04] "explode" is PHP's "split", splitting on a space, we create a list ($words) of "January", "11th". Then we convert the first item in that list (the month) into all caps. [05]
[01] $currentMonth represents the last month which we wrote a header for. When the script starts, it's set to "". For every record, we check [07] if the record's month (in all caps) is the same as the last header we wrote. If it isn't, we output a header [09] and remember which header was output last [08].
This approach relies very much on your records being in order. ;)
I hope this helps! :)
Chris
Re: [chris] Organizing Lists
this is what I have now.
<?php foreach ($agendasRecords as $record): ?>
<p><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?><br /><span class="agendadate"><?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?></span></a></p><?php endforeach; ?>
Creative Director
JAM Graphics
Re: [jtedescojam] Organizing Lists
By Chris - February 5, 2010
Sure thing, all you need to do is replace these two lines:
<?php $words = explode(" ", $record['month_day']); ?>
<?php $monthNameInCaps = strtoupper(@$words[0]); ?>
with this:
<?php $monthNameInCaps = strtoupper(date('F', strtotime($record['date']))); ?>
Chris
Re: [chris] Organizing Lists
While I'm at it... I'm trying to do something similar inside of Policies page... but instead of a month header to break up different months, I need a Policy title to break up different sets of policies... so right now I have a drop down to select which category of policies (10 options), then on the page I have 10 sets of viewer code, each with it's own specific filter... and 10 of these...
<p class="policyheader">0000 - Bylaws</p>
<?php foreach ($policies0000Records as $record): ?>
<p><?php foreach ($record['document'] as $upload): ?><a href="<?php echo $upload['urlPath'] ?>"><?php echo $record['policy_number'] ?> - <?php echo $record['policy_title'] ?></a><?php endforeach ?></p><?php endforeach ?>
<p class="policyheader">1000 - Administration</p>
<?php foreach ($policies1000Records as $record): ?>
<p><?php foreach ($record['document'] as $upload): ?><a href="<?php echo $upload['urlPath'] ?>"><?php echo $record['policy_number'] ?> - <?php echo $record['policy_title'] ?></a><?php endforeach ?></p><?php endforeach ?>
<?php if (!$policies1000Records): ?>
<p>Please be patient while we re-structure this section.</p>
<?php endif ?>
And so on.... if you can do this today, excellent! otherwise.. have a great weekend and thanks for assistance thus far.
http://www.pequannock.org/district/board-of-education/policies.php
Creative Director
JAM Graphics
Re: [jtedescojam] Organizing Lists
By Chris - February 5, 2010
Can you please post the top of that file? I'd need to know which field you're filtering on.
Chris