📜 ⬆️ ⬇️

MODx - news archive in the form of a calendar (simplified version)

So let's start with the fact that many who work with MODx, sooner or later face the fact that no matter how comfortable Ditto is, but, nevertheless, he cannot do many things, one of which, in my opinion, should be In general, in the basic features - an archive of news in the form of a calendar, for example:

image

At the moment, unfortunately, there is only a simplified solution to this problem: DittoCal. You can always download it here .
Why simplified? Yes, because the snippet does not know how to show several news at once for the same date, but displays the very first one, but for some it’s not necessary anymore, so let's get started.
')

After downloading the archive, we will see 2 files in it: JSON.php and snippet.DittoCal.php, go to MODx and create a new “DittoCal” snippet, copy the contents of the snippet.DittoCal.php file into it. Open our ftp and create a new folder “DittoCal” in assets / snippets, then upload the JSON.php file to it.

Now the most interesting: how it all works.

1. Create a new document with the following parameters:
Headline: blog json output
Nickname: blog-json-output
Template: blank
Show in menu: no
Post: yes
Searchable: no
Content Type: text / plain
2. In the content we write:
[!Ditto? startID=`id____` &summarize=`100` &format=`json` &dateFormat=`%d-%m-%Y` &sortDir=`desc`!]
3. Save the document
4. Paste our calendar call somewhere:
[!DittoCal? &calSource=`_./blog-json-output` &dayNameLength=`1`!]

Everything, you can enjoy our calendar:
image

But in the picture he is Russian, but I don’t! This happens, even though the snippet has a function responsible for the regional settings of the calendar, but it does not always work, so the next point: Russification .

1. Open snapshot DittoCal in MODx.
2. Looking for a line
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
And add after it
switch(ucfirst($month_name))
{
case "January": $title=""; break;
case "February": $title=""; break;
case "March": $title=""; break;
case "April": $title=""; break;
case "May": $title=""; break;
case "June": $title=""; break;
case "July": $title=""; break;
case "August": $title=""; break;
case "September": $title=""; break;
case "October": $title=""; break;
case "November": $title=""; break;
case "December": $title=""; break;
}
$title.=' '.$year;

3. We are looking for:
foreach($day_names as $d)
$calendar .= ''.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'';

and replace with
$calendar .= '';
$calendar .= '';
$calendar .= '';
$calendar .= '';
$calendar .= '';
$calendar .= '';
$calendar .= '';


Everything. Now the calendar is Russified.
For those who do everything as it is written, but still everything is in English or does not work at all, I will give here a link to the full code of the snippet already Russified: DittoCalRus

Now it would be nice to stylize it, well, there is nothing complicated at all to save you time, I offer a ready-made version of CSS :

/*********************************************
CSS
*********************************************/
table.calendar {
width: 182px;
padding: 0px;
margin: 0px auto;
margin-bottom: 5px;
border-left: 1px solid #A2ADBC;
font: bold 12px/20px;
text-align: center;
background-color: #EEE;
color: #888888;
}
.calendar-prev, .calendar-prev a, .calendar-next, .calendar-next a {
font-size: 24px;
text-align: center;
text-decoration: none;
}
caption.calendar-month {
margin: 0px auto;
margin-top: 5px;
padding: 5px 0px;
width: 182px;
color: #8e2c3a;
font-size: 18px;
text-align: center;

}
table.calendar th {
font-size: 16px;
color: #616B76;
width: 26px;
height: 25px;
border-right: 1px solid #A2ADBC;
border-bottom: 1px solid #A2ADBC;
border-top: 1px solid #A2ADBC;
text-align: center;
}
table.calendar td {
border-right: 1px solid #A2ADBC;
border-bottom: 1px solid #A2ADBC;
width: 26px;
height: 25px;
text-align: center;
}
table.calendar td a {
text-decoration: none;
font-weight: bold;
display: block;
font-size:100%;
}
table.calendar td a:link, table.calendar td a:visited {
color: #000;
}
table.calendar td a:hover, table.calendar td a:active {
color: #8e2c3a;
}


So, we get this:
image

At the request of users, I will add an example of use, so that the work of the archive would be clear:
Sample on muddydogpaws.com

All pleasant enjoy, thank you!
ZY: maybe the time will appear the other day, then I'll try to see what can be done with the output of several news for one date.

Appendix - Parameters DittoCal

&calSource
: ,
: [ URI ]
: , (.. : www.mysite.ru/blog-json-output)
&linkClass
: cal_link
: [ string ]
: (td), .
&dayNameLength
: 3
: [ 0 | 1 | 2 | 3 | 4 ]
: (4 - ).
&firstDay
: 0
: [ 0 | 1 | 2 | 3 | 4 | 5 | 6 ]
: . 0=, 1=, ....
&showPn
: 1
: [ 0 | 1 ]
: / .
&debug
: 0
: [ 0 | 1 ]
: , 1 - .
&ph
: cal_link
: [ string ]
: , .
&activeDay
: curDay
: [ string ]
: , .

Source: https://habr.com/ru/post/91062/


All Articles