I've changed the sidebar and category files. The first loop runs months archives up to the max amount of months (to not load all of them) and the next runs the yearly archives.
To check the amount of months, run
$monthcount = date('m')Add the following code to the bottom of the first loop to remove the other year's months
<script type="text/javascript">
var currentyear = new Date();
var thisyear = currentyear.getFullYear(); // get the current year
// Hide the previous year posts
var myDiv = document.getElementById("monthlyar"); // get the div
var myListItems = myDiv.getElementsByTagName('li'); //get all li's with the entries'
for (var i=0;i<myListItems.length; i++)
{
var li_item = myListItems[i].innerHTML; // get the inner text of each li
if (li_item.indexOf(thisyear) < 0) // if not current year
{
// hide them
myListItems[i].style.display = 'none';
}
}
</script>
Hide the current year and show the other years
<script type="text/javascript">
// Hide this year or make them bold
for (var j=0;j<myListItems.length; j++)
{
var li_item = myListItems[j].innerHTML; // get the inner text of each li
if (li_item.indexOf(thisyear) >= 0 && li_item.indexOf('January') < 0 && li_item.indexOf('February') < 0 &&
li_item.indexOf('March') < 0 && li_item.indexOf('April') < 0 && li_item.indexOf('May') < 0 &&
li_item.indexOf('June') < 0 && li_item.indexOf('July') < 0 && li_item.indexOf('August') < 0 &&
li_item.indexOf('September') < 0 && li_item.indexOf('October') < 0 && li_item.indexOf('November') < 0 &&
li_item.indexOf('December') < 0) // if contains current year and not contain months
{
//hide them
myListItems[j].style.display = 'none';
}
if (li_item.indexOf('January') < 0 && li_item.indexOf('February') < 0 && li_item.indexOf('March') < 0 &&
li_item.indexOf('April') < 0 && li_item.indexOf('May') < 0 && li_item.indexOf('June') < 0 &&
li_item.indexOf('July') < 0 && li_item.indexOf('August') < 0 && li_item.indexOf('September') < 0 &&
li_item.indexOf('October') < 0 && li_item.indexOf('November') < 0 && li_item.indexOf('December') < 0) // if not contain months
{
myListItems[j].style.fontWeight = 'bold';
}
}
</script>
To be able to show the posts related to the category, install Archives for a category, and you can add an additional argument to load links to the category's archive and hide the other months or years that do not contain that category posts
No comments:
Post a Comment