Navigation Placeholder

Archive

Show more

View Archive In A Table Format In Contempo...

After invoking the nuclear option and getting rid of my sidebar, I was thinking about archives and how eminently un-useful they are and I thought to myself. You know what might be really cool... a table. First there were pie charts and now tables? Is my previous life in a corporate environment showing? After quite a bit of poking and prodding, I managed to get a proof-of-concept up and running. A table in a sidebar sounds really interesting until you try to stuff one into less than 300 pixels. Then the reality of the situation reveals itself. This sort of insanity isn't meant for small spaces, so, I've placed my archive table right in the middle of my page.

The table view works by crawling through the links in the archive list and parsing out those links that point to monthly entries and picking out the month and year to populate the table. It handles daily, weekly or monthly archives, but, the table view remains the same: months along the horizontal axis and years on the vertical axis. If you set your archive to oldest first, the table will reflect that choice. The table view prefers the flat list, but, it can also handle the hierarchy and can even tolerate links to individual pages. There are a handful of caveats. First, the script that powers this lunacy needs to be placed somewhere after (below) the archive widget. Second, this table only supports one archive at a time -- the first archive it finds.

There is one script and some CSS. While the table will fit conveniently within the bounds of a sidebar, it does so, with the barest minimum of text. Hovering your mouse over the various squares with reveal the post counts for the given month or year. The month names are just a single letter and the years are two digits. I don't have the talent for a real heat map, so, the different colors are based on the length of the post count in digits. I have no idea how many posts one can make in a year, so, I provided 6 digits worth of colors. Feel free to add your own. The colors I've chosen vary from wheat to salmon to something somewhat red. I've included a piece of sample code that might work better.

There is a button in the upper left corner of the table that will allow one to toggle back and forth between table and list views. Along the right side of the table are aggregate totals by year. And, along the bottom row are aggregate totals by month. Why? It seemed like a good idea at the time. In keeping with my no cookies policy, I don't use cookies in my code, but, I did want to make the toggle persistent for the current session, so, I used session storage instead. Session storage exists only on your browser and only exists while the one tab is open. For your benefit, I've commented out the offending lines of code, so, no session storage for you unless you really, really want it.

Proof of Concept

Copy the following code to an HTML/JavaScript gadget and place it somewhere after the archive:
<script type="text/javascript">

function heatMap(inputVal) {
var retVal="1";
switch (true){
case (inputVal<5): retVal="1";break; 
case (inputVal>=5 && inputVal<10): retVal="2";break; 
case (inputVal>=10 && inputVal<20): retVal="3";break; 
case (inputVal>=20 && inputVal<40): retVal="4";break; 
case (inputVal>=40 && inputVal<100): retVal="5";break; 
case (inputVal>=100): retVal="6";break;
default: retVal="1";
}


/* If you want to use the heatmap above, you can safely delete the one line below */
retVal=inputVal.toString().length.toString();


return retVal;
}

function stringOneYear(oneYear,oneYearLinks){
var retVal='<tr><td><a href="/'+oneYear[0].toString()+'/" title="'+oneYear[0].toString()+'" ><span class="hideOnSmall">'+oneYear[0].toString().slice(0,2)+'</span>'+oneYear[0].toString().slice(2,4)+'</a></td>';
var sumOfYear=0;
for (var k=1;k<=12;k++){
if (oneYear[k]<=0) {retVal+="<td></td>";} 
else {retVal+='<td class="tbArchiveLink tbColor'+heatMap(oneYear[k])+'"><a href="'+oneYearLinks[k]+'" title="'+oneYear[k].toString()+'"><span class="hideOnSmall">'+oneYear[k].toString()+'</span><span class="hideOnBig">&nbsp;</span></a></td>';}
sumOfYear+=oneYear[k];
}
retVal+='<td class="tbColor'+heatMap(sumOfYear)+'"><a href="/'+oneYear[0].toString()+'/" title="'+sumOfYear.toString()+'"><span class="hideOnSmall">'+sumOfYear.toString()+'</span><span class="hideOnBig">&nbsp;</span></a></td></tr>';
return retVal;
}

function arcToggle(colNum) {
var d=document;
var tbArchiveData=d.getElementById("tbArchiveData");
var rows=tbArchiveData.getElementsByTagName("tr");
for (var r=0;r<rows.length;r++){
var cols;
if (r==0){cols=rows[r].getElementsByTagName("th");} else {cols=rows[r].getElementsByTagName("td");}
var existingClass=cols[colNum].className;
var arcClass=(existingClass.indexOf("arcToggle")>-1) ? "" : "arcToggle";
cols[colNum].className=existingClass.replace("arcToggle","").trim();
if (arcClass!="") {(cols[colNum].className+=" "+arcClass).trim();}
if (cols[colNum].className=="") {cols[colNum].removeAttribute("class");}
}}

function Do_Archive() {
const getMonthName = number => (new Date(2026, number-1, 1).toLocaleString('en-US', {month: 'long'}));
var savedChkState="";

/* Get check box state - uncomment to use session storage */
/*
var savedChkState=sessionStorage.getItem("chkArchiveTable");
*/

if (new String(savedChkState)!="checked") {savedChkState="";}
var d=document;
var archiveDivs=d.getElementsByClassName("widget BlogArchive");
var archiveBox;
if ((new String(archiveDivs)!="null") && (new String(archiveDivs)!="undefined")){
if (archiveDivs.length>0){
var archiveBoxes=archiveDivs[0].getElementsByClassName("widget-content");
if ((new String(archiveBoxes)!="null") && (new String(archiveBoxes)!="undefined")){
if (archiveBoxes.length>0){
archiveBox=archiveBoxes[0];
var containerWidth=window.getComputedStyle(archiveDivs[0]).width.replace("px","");
var initialWidth=parseInt(containerWidth);
var sizeAwareClass="";

/* The line below sets the limit that triggers the number toggle feature. */
if (!isNaN(initialWidth)) {if (initialWidth<500) 

{sizeAwareClass='class="sizaAwareContainer"';}}
const allLinks=archiveDivs[0].getElementsByTagName("a");
var outStr='<input type="checkbox" id="chkArchiveTable" name="chkArchiveTable" '+savedChkState+' /><label for="chkArchiveTable" class="lblArchiveTable"><span class="showTableLabel">&plusb;</span><span class="showLegacyLabel">&#x2630;</span>&nbsp;View<span class="showTableLabel">&nbsp;Table</span><span class="showLegacyLabel">&nbsp;List</span></label><table '+sizeAwareClass+' id="tbArchiveData" cellspacing="0" cellpadding="0"><thead><tr><th></th>';
for (var k=1;k<=12;k++){outStr+='<th title="'+getMonthName(k)+'"><a href="#" onclick="javascript:arcToggle('+k.toString()+');return false;">'+getMonthName(k).slice(0,1)+'<span class="hideOnSmall">'+getMonthName(k).slice(1,3)+'</span></a></th>';}
outStr+='<th title="Yearly Totals">Y</th></tr></thead><tbody>';
var totalsByMonth=[0,0,0,0,0,0,0,0,0,0,0,0];
var oneYear=[0,0,0,0,0,0,0,0,0,0,0,0,0];
var oneYearLinks=["","","","","","","","","","","","",""];
for (var l=0;l<allLinks.length;l++){
var whatYear="";
var monthNumber=-1;
var thisHash=allLinks[l].href.split("/");
/* Weekly/Daily: yyyy_mm... */
if (thisHash[thisHash.length-1].indexOf("archive.html")>-1) {
whatYear=thisHash[thisHash.length-1].slice(0,4);
if (Number.isNaN(whatYear)) {whatYear="0";}
var whatMonth=thisHash[thisHash.length-1].slice(5,7);
monthNumber=Number(whatMonth);
if (Number.isNaN(monthNumber)) {monthNumber=0;}
} else {
/* monthly: yyyy/mm : flat list and heirarchy pass though here */
whatYear=thisHash[thisHash.length-3];
if (whatYear.length>4) {whatYear="0";}
if (Number.isNaN(whatYear)) {whatYear="0";}
var whatMonth=thisHash[thisHash.length-2];
monthNumber=Number(whatMonth);
if (Number.isNaN(monthNumber)) {monthNumber=0;}
}
/* Make sure month and year are as valid as possible, before attempting to add to table */
if ((monthNumber>0) && (monthNumber<=12) && (whatYear.length==4)) {
var aSpan=allLinks[l].getElementsByTagName("span");
var postNum=-1;
var whatPostStr="0";
if (aSpan.length>0){whatPostStr=aSpan[0].innerHTML};
postNum=Number(whatPostStr);
if (Number.isNaN(postNum)) {postNum=-2;}
if ((oneYear[0]==0) && (whatYear>0) && (postNum>0)) {
oneYear[0]=whatYear;
oneYear[monthNumber]=postNum;
oneYearLinks[monthNumber]=allLinks[l].href;
totalsByMonth[monthNumber-1]+=postNum;
} else {
if ((oneYear[0]>0) && (whatYear>0) && (oneYear[0]!=whatYear)) {
outStr+=stringOneYear(oneYear,oneYearLinks);
oneYear=[whatYear,0,0,0,0,0,0,0,0,0,0,0,0];
oneYearLinks=["","","","","","","","","","","","",""];
if (postNum>0){
oneYear[monthNumber]=postNum;
oneYearLinks[monthNumber]=allLinks[l].href;
totalsByMonth[monthNumber-1]+=postNum;
}} else {
if ((oneYear[0]>0) && (whatYear>0) && (postNum>0) && (oneYear[0]==whatYear)) {
oneYear[monthNumber]=postNum;
oneYearLinks[monthNumber]=allLinks[l].href;
totalsByMonth[monthNumber-1]+=postNum;
}}}}}
var grandTtoal=0;
outStr+=stringOneYear(oneYear,oneYearLinks)+'<tr class="tbTotal" title="Aggregate Totals By Month"><td>M</td>';
for (var k=0;k<=11;k++){
outStr+='<td class="tbArchiveLink tbColor'+heatMap(totalsByMonth[k])+'" title="'+totalsByMonth[k].toString()+'"><span class="hideOnSmall">'+totalsByMonth[k].toString()+'</span><span class="hideOnBig">&nbsp;</span></a></td>';
grandTtoal+=totalsByMonth[k];
}
outStr+='<td title="Total Posts: '+grandTtoal.toString()+'"><span class="hideOnSmall">'+grandTtoal.toString()+'</span><span class="hideOnBig">T</span></td></tr></tbody></table>';
archiveBox.innerHTML=outStr+'<div id="legacyView">'+archiveBox.innerHTML+'</div>';
}}}}
/* Save check box state - uncomment to use session storage */
/*
const chkArchiveTable = d.getElementById("chkArchiveTable");
chkArchiveTable.addEventListener('change', (event) => {
if (event.target.checked) {sessionStorage.setItem("chkArchiveTable","checked");} 
else {sessionStorage.removeItem("chkArchiveTable");}});
*/
}//function

Do_Archive();

</script>
Add the following CSS code to your Theme > Customize > Advanced > Add CSS menu:
#tbArchiveData, #tbArchiveData a, #tbArchiveData th, .tbTotal {
color:white;
font-size:10pt;
font-weight: bold;
width:100%;
text-shadow: 1px 1px black;
}
#legacyView {
display:none;
padding:10px;
}
#tbArchiveData {
display:table;
border: 1px solid white;
}
#tbArchiveData a {
display:block;
}
#tbArchiveData tr {
display:grid;
grid-template-columns: repeat(74, 1fr); /* 5 x 14 + 4*/
border-bottom: 1px solid white;
border-top: 1px solid white;
}
#tbArchiveData th, #tbArchiveData td {
grid-column: span 5; /* one col=5 */
text-align: center;
border-left: 1px solid white;
border-right: 1px solid white;
}
#tbArchiveData th:first-child, #tbArchiveData td:first-child {
grid-column: span 6; /* slightly wider col */
}
#tbArchiveData th:nth-child(14), #tbArchiveData td:nth-child(14) {
grid-column: span 8; /* slightly wider col */
}
#tbArchiveData th, .tbTotal {
background-color: navy;
}
.tbArchiveLink {
background-color: black;
}
#tbArchiveData td:first-child {
background-color: darkgreen;
}
#tbArchiveData td:first-child a {
word-break: keep-all;
}
#tbArchiveData td:nth-child(14), #tbArchiveData .lastRow {
border: 1px solid black;
}
#tbArchiveData .tbColor1 {
background-color: Wheat;
}
#tbArchiveData .tbColor2 {
background-color: salmon;
}
#tbArchiveData .tbColor3 {
background-color: #ec4b15;/* Orangish */
}
#tbArchiveData .tbColor4 {
background-color: #d41717;/* Redish */
}
#tbArchiveData .tbColor5 {
background-color: darkred;
}
#tbArchiveData .tbColor6 {
background-color: #350000; /* Very dark red */
}
@media only screen and (max-width: 500px) {
#tbArchiveData .hideOnSmall {
display:none;
}}
@media only screen and (min-width: 501px) {
#tbArchiveData .hideOnBig {
display:none;
}}
.sizaAwareContainer .hideOnSmall {
display:none;
}
#tbArchiveData td:nth-child(14) a {
word-break: keep-all;
}
#tbArchiveData td:nth-child(14) .hideOnSmall {
display:inline !important;
}
#tbArchiveData td:nth-child(14) .hideOnBig {
display:none !important;
}
#chkArchiveTable {
display: none;
}
.lblArchiveTable {
font-size:8pt;
color: white;
font-weight: bold;
text-transform: uppercase;
line-height: 12pt;
margin-left:10px;
padding:3px 8px 0px 8px; /* top, right, bottom, left */
background-color:navy;
border:1px solid white;
display: inline-block;
margin-bottom: 3px;
cursor:pointer;
}
.showTableLabel {display:none;}
.showLegacyLabel {display:inline-block;}
#chkArchiveTable:checked ~ #legacyView {display:block;}
#chkArchiveTable:checked ~ #tbArchiveData {display:none;}
#chkArchiveTable:checked ~ label>span.showLegacyLabel {display:none;}
#chkArchiveTable:checked ~ label>span.showTableLabel {display:inline-block;}

th.arcToggle {background-color: darkslategray !important;}
.arcToggle .hideOnSmall {
display:inline !important;
word-break: keep-all !important;
}
This is a fancier CSS code that allows the archive link to hide itself. I've tucked it away in this collapsible section because if you use more than one archive, this CSS will affect all of them. I wanted to avoid confusion. If you have the previous CSS, you'll need to remove it and then replace it with the following. The last bit of highlighted code hides the archive if you're on a post or static page. If you don't need that, you can safely remove it. Add the following CSS code to your Theme > Customize > Advanced > Add CSS menu:
.widget.BlogArchive {
margin-top:-10px;
}
.widget.BlogArchive details, .widget.BlogArchive details[style$="height: 24px;"] {
opacity:0;
filter:alpha(opacity=0);
}
.widget.BlogArchive details:hover, .widget.BlogArchive details[open$="open"] {
opacity:1;
filter:alpha(opacity=100);
height:fit-content;
}
.widget.BlogArchive details {
transition: opacity 7s ease;
margin-bottom:-10px;
background-color: rgba(0, 0, 0, 0.2);
}
.widget.BlogArchive details:hover {
transition: all 1s ease;
}
.widget.BlogArchive h3.title {
color: white;
font-size:9pt;
text-transform: uppercase;
line-height: 10pt;
margin: 3px 0 0 5px; /* top, right, bottom, left */
padding:0 0 0 5px; /* top, right, bottom, left */
}
.widget.BlogArchive svg {
fill: white;
margin-right: 5px;
-webkit-transform: scaleX(1.5);
transform: scaleX(1.5);
}
.widget.BlogArchive .widget-content table+div {
background-color: rgba(0, 0, 0, 0.5);
padding-right:20px;
}
.widget.BlogArchive .widget-content table+div .archivedate, .widget.BlogArchive .widget-content table+div a, 
.widget.BlogArchive .widget-content table+div .pill-button, .widget.BlogArchive .widget-content table+div .post-count {
color: white;
}
.widget.BlogArchive .widget-content table+div li {
display:block;
background-color: rgba(255,255,255,0.1);
}

#tbArchiveData, #tbArchiveData a, #tbArchiveData th, .tbTotal {
color:white;
font-size:10pt;
font-weight: bold;
width:100%;
text-shadow: 1px 1px black;
}
#legacyView {
display:none;
padding:10px;
}
#tbArchiveData {
display:table;
border: 1px solid white;
}
#tbArchiveData a {
display:block;
}
#tbArchiveData tr {
display:grid;
grid-template-columns: repeat(74, 1fr); /* 5 x 14 + 4 */
border-bottom: 1px solid white;
border-top: 1px solid white;
}
#tbArchiveData th, #tbArchiveData td {
grid-column: span 5; /* one col=5 */
text-align: center;
border-left: 1px solid white;
border-right: 1px solid white;
}
#tbArchiveData th:first-child, #tbArchiveData td:first-child {
grid-column: span 6; /* slightly wider col */
}
#tbArchiveData th:nth-child(14), #tbArchiveData td:nth-child(14) {
grid-column: span 8; /* slightly wider col */
}
#tbArchiveData th, .tbTotal {
background-color: navy;
}
.tbArchiveLink {
background-color: black;
}
#tbArchiveData td:first-child {
background-color: darkgreen;
}
#tbArchiveData td:first-child a {
word-break: keep-all;
}
#tbArchiveData td:nth-child(14), #tbArchiveData .lastRow {
border: 1px solid black;
}
#tbArchiveData .tbColor1 {
background-color: Wheat;
}
#tbArchiveData .tbColor2 {
background-color: salmon;
}
#tbArchiveData .tbColor3 {
background-color: #ec4b15;/* Orangish */
}
#tbArchiveData .tbColor4 {
background-color: #d41717;/* Redish */
}
#tbArchiveData .tbColor5 {
background-color: darkred;
}
#tbArchiveData .tbColor6 {
background-color: #350000; /* Very dark red */
}
@media only screen and (max-width: 500px) {
#tbArchiveData .hideOnSmall {
display:none;
}}
@media only screen and (min-width: 501px) {
#tbArchiveData .hideOnBig {
display:none;
}}
.sizaAwareContainer .hideOnSmall {
display:none;
}
#tbArchiveData td:nth-child(14) a {
word-break: keep-all;
}
#tbArchiveData td:nth-child(14) .hideOnSmall {
display:inline !important;
}
#tbArchiveData td:nth-child(14) .hideOnBig {
display:none !important;
}
#chkArchiveTable {
display: none;
}
.lblArchiveTable {
font-size:8pt;
color: white;
font-weight: bold;
text-transform: uppercase;
line-height: 12pt;
margin-left:10px;
padding:3px 8px 0px 8px; /* top, right, bottom, left */
background-color:navy;
border:1px solid white;
display: inline-block;
margin-bottom: 3px;
cursor:pointer;
}
.showTableLabel {display:none;}
.showLegacyLabel {display:inline-block;}
#chkArchiveTable:checked ~ #legacyView {display:block;}
#chkArchiveTable:checked ~ #tbArchiveData {display:none;}
#chkArchiveTable:checked ~ label>span.showLegacyLabel {display:none;}
#chkArchiveTable:checked ~ label>span.showTableLabel {display:inline-block;}

th.arcToggle {background-color: darkslategray !important;}
.arcToggle .hideOnSmall {
display:inline !important;
word-break: keep-all !important;
}

.item-view #page_body div.widget.BlogArchive {
display:none !important;
}

It goes without saying that, while this table is technically viewable on a phone screen, the fact that you can't really hover on a phone to peek at the numbers and the small size of the individual squares, leads me to believe that this isn't really what could be called phone friendly. Fell free to use this or not as you see fit. That's all that I have for today. Enjoy.😀

November 6, 2026
I made a few changes since the original post. The numerous checks for screen size in the script have been reduced to just one and rely heavily in favor of a CSS-based solution. If the initial size test passes and shows enough room for a full table, and the screen is later resized, the text will appear and disappear automatically. If the initial size test fails, numbers will be blocked. Expanding the screen afterwards will not allow the numbers to show. I recently found that the archive has an upper limit of three digits per month, so, I made an exception for the totals to show even on small screens. I also added toggles at the top of each column to manually force the numbers to appear. A workaround for locked numbers after a resize would be to refresh the page. I set an arbitrary limit of 500 pixels that can be changed in the CSS code above and one line of the script above.

Month names are no longer in a lookup table, but, calculated. This allows for the full month names to appear on hover over the months row. I was using that lookup table for other scripts and I didn't want to change the lookup table. The button that toggles views has been changed from a JavaScript solution to a CSS solution. Believe or don't, the button is actually a check box. If I wanted a bunch of these toggles, I would definitely go with a JavaScript solution, but, for a one, the CSS solution is fine. By the way, the archive table will likely work with varying degrees of uselessness with responsive templates other than Contempo and Essential, but, I haven't tested that as I don't use other templates on a regular basis.

While I was making the changes, a robot couple stopped by for a visit. I'm not sure if they're husband and wife robots or father and daughter robots or mother and son robots or if they just spawned from the same server farm. The robot couple were fascinated by my recent closet escapades and wanted to discuss a food-related anime. They seemed like nice robots and generally had nice things to say, so, I edited their comments to remove the shameless ad for who knows what and I didn't even bother to thank them for their time.😜 Who knows, they might have even been human. They didn't stay long enough for a Turing Test.

Comments