This new script will automate archive linking!
Code:
<?php
function get_i18n_archive($tag='news', $maximum='9999', $url='/index.php?id=search&', $wrap='span') {
$array = return_i18n_search_results($tags=$tag, $words=null, $first=0, $max=$maximum, $order='created', $lang=null);
$results = $array['results'];
$current_date = null;
foreach ($results as $entry) {
$month_year = strftime('%B %Y', $entry->creDate); // formats date as MONTH YEAR (e.g. June 2009)
if ($month_year != $current_date) {
$current_date = $month_year; // changes current month only if it differs from the previous entry
$m = strftime('%m', $entry->creDate); // defines 2-digit month (e.g. February is 02, October is 10)
$y = strftime('%Y', $entry->creDate); // defines 4-digit year (e.g. 2009, 2012)
if ($wrap=='' || $wrap==null) { $wrap = 'span'; } // sets wrap to a span if no value is given
echo '<'.$wrap.' class="archive-link" value="'.$url.'&tags=_cre_'.$y.$m.'+'.$tag.'"><a href="'.$url.'&tags=_cre_'.$y.$m.'+'.$tag.'">'.$current_date.'</a></'.$wrap.'>';
} // end if
} // end foreach
} // end function
?>
To use, simply paste the above into your desired component or simply in a template file called 'functions.php', and call it with the following:
Code:
<php get_i18n_archive(); ?>
This outputs the links to the months of the archive in the form "Month Year" (e.g.
July 2012), and so long as you have a page with the
(% searchresults %) placeholder on it, the links will work (though you need to set the URL prefix correctly - this is explained below). The following parameters can be passed to the function within the ():
- $tag - sets the tag that I18N Search searches for. By default it is set to 'news' - virtual tags (with the underscore _) can be used as well.
- $maximum - sets the max results. Set to 9999 by default so that (in vast majority of most cases) the whole archive can be seen - you can reduce this number to only show a set number of links.
- $url - sets the url prefix for the links. By default it is /index.php?id=search& so that it works even for those without pretty urls enabled (it points to their 'search' page), but you can pick whatever prefix you like (so long as it pointed to a page with the (% searchresults %) placeholder on it)
- $wrap - for styling, this sets what tags (span, div, li, ol, etc...) wrap the anchor. I put this in mainly because I initially used a dropdown box for my archive, so this makes it easier to do so - all you need to do is wrap the whole function in a <select> tag and set $wrap to 'option'.
Example:
Code:
<?php get_i18n_archive($tag='_special_blog', $maximum='100', $url='/blog/', $wrap='div') ?>
Will search for pages with the virtual tag
_special_blog (which is automatically generated for special pages of the type 'blog'), index a maximum of
100 search results; said links will be of the type
"domain.com/blog/?tags=tags=_cre_YYYYMM+_special_blog" and each link will be wrapped in a
div.