[SOLVED] News Archives by Year/Month
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
Re: News Archives by Year/Month
blast, are you God?
Re: News Archives by Year/Month
sam_butler wrote: blast, are you God?
what do you mean?
Last edited by blast2007 on Thu Jul 24, 2008 12:08 pm, edited 1 time in total.
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
Re: News Archives by Year/Month
Sorry, haha, I just meant your solution was excellent. I guess British jokes don't work with Italians
Will install the diff soon and let you know how it goes. Thanks again.
Will install the diff soon and let you know how it goes. Thanks again.
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
Re: News Archives by Year/Month
Wow, I've been busy. Okay, here's what I did:
1) Installed the patch from the diff (see above) so I can set start/end dates for a news summary;
2) Created a new page with the alias 'news-archive' as a child of 'news';
3) Thought a little bit, then realised the best way to do it without creating a new page for each year would be to pass a variable in the query string...
4) Wrote a UDT called 'news_archive_setup':
5) Didn't quite get it right, had to learn the hard way that you can't concatenate strings in smarty (at least not easily), learned how to assign variables to smarty, and finally came up with the simple code above (I could add some regex to check that what was entered was an integer of four digits, but it's not needed right now);
6) Put the following in the content of my archives page:
7) I did this before, but if someone else wants to use the variable 'detail_title' as assigned in the UDT, here's what I have in the of my template:
8 ) Created a sidebar with links to each of the years of the archive (I was going to write something to make this dynamic based on what years there are news items for, but I ran out of time) like this:
The heading of this sidebar appears down the page, so it's anchored as 'archives', which is linked to with the smarty {anchor} in the content above. Also there's an {if} statement in my template to display the news archive sidebar in place of the last three articles if you're on the news summary page or an archive page. (Oh, and I thought after that the easiest way to make the list of links, since I'm doing it with yearly archives, would be to have a UDT to loop through from an arbitrary starting year, in my case 2003, until it reaches date('Y').)
9) Rejoiced and moved on to satisfy the next of my client's desires.
Thanks to all who helped, and I'll accept any suggestions for improving the efficiency of the solution I came up with based on the contribs here. Main thing is it works FINALLY!
1) Installed the patch from the diff (see above) so I can set start/end dates for a news summary;
2) Created a new page with the alias 'news-archive' as a child of 'news';
3) Thought a little bit, then realised the best way to do it without creating a new page for each year would be to pass a variable in the query string...
4) Wrote a UDT called 'news_archive_setup':
Code: Select all
global $gCms;
global $smarty;
if (!isset($_GET['year']) || $_GET['year'] == "") {
$archiveyear=date('Y');
}
else {
$archiveyear=$_GET['year'];
}
$startperiod="{$archiveyear}/01/01";
$endperiod="{$archiveyear}/12/31";
$title="News Archive ".$archiveyear;
$smarty->assign('archiveyear', $archiveyear);
$smarty->assign('startperiod', $startperiod);
$smarty->assign('endperiod', $endperiod);
$smarty->assign('detail_title', $title);
6) Put the following in the content of my archives page:
Code: Select all
{news_archive_setup}
<h3 class="center">{title} – {$archiveyear}</h3>
<p style="text-align: center;">{anchor anchor="archives" title="News Archives" text="Choose another year"}</p>
{news summarytemplate="archive" detailpage="view-news" startperiod=$startperiod endperiod=$endperiod sortasc="true"}
Code: Select all
{if isset($detail_title)}
<title>{$detail_title} - {sitename}</title>
{else}
<title>{title} - {sitename}</title>
{/if}
Code: Select all
<a title="News Archive 2008" href="{cms_selflink href='news-archive'}?year=2008">2008</a>
9) Rejoiced and moved on to satisfy the next of my client's desires.
Thanks to all who helped, and I'll accept any suggestions for improving the efficiency of the solution I came up with based on the contribs here. Main thing is it works FINALLY!
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
Re: News Archives by Year/Month
Yeah, I did that just now... UDT called 'news_archive_sidebar' with comments:sam_butler wrote:Oh, and I thought after that the easiest way to make the list of links, since I'm doing it with yearly archives, would be to have a UDT to loop through from an arbitrary starting year, in my case 2003, until it reaches date('Y').
Code: Select all
//Execute some smarty code to make the archive link
global $gCms;
$smarty = &$gCms->GetSmarty();
$smarty_data = "{cms_selflink href='news-archive'}"; //this is the archive link
$smarty->_compile_source('temporary template', $smarty_data, $_compiled );
@ob_start();
$smarty->_eval('?>' . $_compiled);
$_contents = @ob_get_contents();
@ob_end_clean();
$archivelink = $_contents;
//Set the first year of archives:
$firstyear=2003;
//Set some variables
$thisyear=date('Y');
$i=$firstyear;
//HTML before the loop
echo "<ul>";
//Loop through the years to this year
while ($i <= $thisyear) {
echo "<li>"; //HTML at beginning of iteration
echo "<a title="News Archive {$i}" href="{$archivelink}?year={$i}">{$i}</a>";
echo "</li>"; //HTML at end of iteration
++$i;
}
//HTML after the loop
echo "</ul>";
Last edited by sam_butler on Thu Jul 31, 2008 4:47 pm, edited 1 time in total.
Re: [SOLVED] News Archives by Year/Month
Why don't change it and say for previous users bla bla bla ...?
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
Re: [SOLVED] News Archives by Year/Month
Sorry Mark, I didn't get you there - change what?mark wrote: Why don't change it and say for previous users bla bla bla ...?
-
- Power Poster
- Posts: 322
- Joined: Sat Feb 04, 2006 1:24 am
- Location: London, England
Re: [SOLVED] News Archives by Year/Month
I think he means modify the code example so that people don't copy and paste it before reading your correction.
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
-
- New Member
- Posts: 5
- Joined: Thu Sep 25, 2008 3:34 pm
Re: [SOLVED] News Archives by Year/Month
Interesting post, as this Word Press-type archive is exactly what we're after with bringing locustvalleyfd.com over to CMSms. Before digging into this too much, I was wondering if...
2. Has there been any update to the News Menu mod that NaN posted above?
Thanks!
1. Has the patch been integrated with latest version (1.4.1 now)?blast2007 wrote: Calguy told me that we have to wait until 1.4 is out before these kind of patches will be integrated in the official module. We hope.
2. Has there been any update to the News Menu mod that NaN posted above?
Thanks!
Re: [SOLVED] News Archives by Year/Month
Since there was no response if it works or not I did no updates yet.
I'm just using this in one single page and there it works like it should.
I'm not going to publish it into the forge since I've read that there will be a solution in the new CMS version.
I'm just using this in one single page and there it works like it should.
I'm not going to publish it into the forge since I've read that there will be a solution in the new CMS version.
-
- New Member
- Posts: 5
- Joined: Thu Sep 25, 2008 3:34 pm
Re: [SOLVED] News Archives by Year/Month
Hi NaN,
Thanks for the reply. Could you post the link to what you've read regarding a solution in next CMS version?
Thank you!
Thanks for the reply. Could you post the link to what you've read regarding a solution in next CMS version?
Thank you!
Re: [SOLVED] News Archives by Year/Month
It was mentioned in the current topic by blast2007
http://forum.cmsmadesimple.org/index.ph ... #msg116827
http://forum.cmsmadesimple.org/index.ph ... #msg116827
Last edited by NaN on Mon Oct 27, 2008 3:21 pm, edited 1 time in total.
Re: [SOLVED] News Archives by Year/Month
mmm....
News module 2.9 (CMSMS 1.5) still misses this most-wanted ready-to-apply patch
...anyone can tell us why?
Regards
blast
News module 2.9 (CMSMS 1.5) still misses this most-wanted ready-to-apply patch
...anyone can tell us why?
Regards
blast
-
- Forum Members
- Posts: 89
- Joined: Thu Aug 21, 2008 11:47 am
Re: [SOLVED] News Archives by Year/Month
Blast,
Any chance of you re-posting the link to the patch? It seems to be a dead link now and I could really do with having this functionality.
Thanks
Any chance of you re-posting the link to the patch? It seems to be a dead link now and I could really do with having this functionality.
Thanks