Many Ways to Archive Contents in WordPress Websites

Posted on January 27, 2008
Filed Under WordPress Coding, WordPress Customization |

Many WP themes provide monthly archive links in the sidebar. This display is realized by PHP code as:

<?php wp_get_archives(’type=monthly’); ?>

The monthly archive is not bad. The problem is, after your blog runs for many months, the archive list becomes really long, - it takes a lot of spaces and looks ugly.

An easy way to fix this problem is to limit the number of archived links in the list. For example, if you want to display only the last 10 months archive, just add limit=10, such as:

<?php wp_get_archives(’type=monthly&limit=10′); ?>

Then this is not really the whole archive.

To make all months of archives available without taking a lot of space, you have make it a drop-down list. The following code can achieve this:

<ul>
<form name=”archiveform” action=”">
<select name=”archive_chrono” onchange=”window.location = (document.forms.archiveform.archive_chrono[document.forms.archiveform.archive_chrono.selectedIndex].value);”>
<option value=”>Monthly Records</option>
<?php get_archives(”,”,’option’, 1); ?>
</select>
</form>
</ul>

So that the monthly archives are in a drop-down list. The list may be very long, but it does not occupy the whole side bar.

As you see, wp_get_archives is the main function to display archive. In addition to “monthly”, the archive type can also be “daily”, “weekly”, or “postbypost”.

Another way to show archive is calendar as found in many blog websites. A simple function wp_get_calendar() will give you the calendar based archive.

Comments

Leave a Reply




*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word