Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Archiving system with I18N News
#1
Angryboy Wrote:One feature that I thought was missing from the i18n News system is that of providing automatic archives for news results. However, such a feat is actually achievable with the current i18n Search plugin if you take a moment to think outside of the box...

Basically it comes down to this:
  • Having a landing page for the archive search results (which can simply be your normal 'search' page)
  • Ensuring that every news entry has a month and a year tag
  • Ensuring that (only) one entry per month has a tag to indicate the monthly archive link
  • Providing a custom output that dynamically produces the links necessary to take you to the appropriate month, showing no other unnecessary information.

http://spritingonawhim.net.tc/articles/g...s/?lang=en
Reply
#2
Angryboy Wrote:
Angryboy Wrote:One feature that I thought was missing from the i18n News system is that of providing automatic archives for news results. However, such a feat is actually achievable with the current i18n Search plugin if you take a moment to think outside of the box...

Basically it comes down to this:
  • Having a landing page for the archive search results (which can simply be your normal 'search' page)
  • Ensuring that every news entry has a month and a year tag
  • Ensuring that (only) one entry per month has a tag to indicate the monthly archive link
  • Providing a custom output that dynamically produces the links necessary to take you to the appropriate month, showing no other unnecessary information.

http://spritingonawhim.net.tc/articles/a...s/?lang=en

hmm, it might be kewl to have a plugin to auto add archive tags to specific pages on save.
month year etc
and this could do all kind of other auto tagging stuff, like keyword count detection and auto tag or heading parsing or something.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
Mvlcek seems to have done this now for the month/year tags :-) I'll need to update my tutorial xD
Reply
#4
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.
Reply
#5
Hi, I'm just trying to get that archive link work. And I'm happy that it does. But the (virtual) special tags in the url doesn't, neither _special_xx nor _cre_yyyymm.

url:
../blog/&tags=_cre_201408+_special_blog

_cre_201408 and _special_blog hav no effect at all

It is working when I'm using a "normal" tag:
../blog/&tags=_cre_201408+blog
but creDate is still not working.

Thanks a lot!
Jo
Reply
#6
Hi,

Is there a way to view the archive like this:

2018 (15) <- count
2019 (20) <- count

Thanks
Reply




Users browsing this thread: 2 Guest(s)