正式サポート

2017-08-03 v 7.1.0 で正式サポートされました。以下とは全く関係無くオプションを指定することで年表示と月表示の切り替えが可能になっています。

https://github.com/open-qhm/qhm/releases


独自に変えてみた

 #qblog_archives プラグインを月を年毎にする。

表示例

Screenshot from 2017-07-27 19:49:43


qblog_archives.inc.php ファイル

<?php
/**
 *   QBlog Achives Plugin
 *   -------------------------------------------
 *   ./plugin/qblog_archives.inc.php
 *
 *   Copyright (c) 2012 hokuken
 *   http://hokuken.com/
 *
 *   created  : 12/07/27
 *   modified : 2017-07-27 i.i 月を年毎にボタンにまとめる
 *              
 *
 *   Description
 *   
 *   
 *   Usage :
 *   
 */
function plugin_qblog_archives_convert()
{
    global $vars, $script, $qblog_close;
 
    //閉鎖中は何も表示しない
    if ($qblog_close && ! ss_admin_check())
    {
        return '';
    }
 
 
    //---- キャッシュのための処理を登録 -----
    $qt = get_qt();
    if($qt->create_cache) {
      $args = func_get_args();
      return $qt->get_dynamic_plugin_mark(__FUNCTION__, $args);
    }
    //------------------------------------
 
    $archives_file = CACHEQBLOG_DIR . 'qblog_archives.dat'; 
    if( file_exists($archives_file) ){
        $archives_list = file_get_contents($archives_file);
        // vvvvv 2016-10-04
        // $lastYear = date("Y", strtotime("-1 year"));
        $lastYear = date("Y", strtotime("-0 year"));
        $lines = explode("\n", $archives_list);
        $ymCount = array();
        $ymCount2 = array();
        for($i=0,$max=count($lines);$i<$max; $i++) {
            list($year, $month, $num) = explode(",", rtrim($lines[$i]));
            if ($year<=$lastYear) {
                if (! isset($ymCount[$year.",0"])) {
                    $ymCount[$year.",0"] = 0;
                }
                $ymCount[$year.",0"] += $num;    // 年毎に件数カウント
                $ymCount2[$year.",".$month] = $num;    // 年月毎に件数カウント
            } else {
                $ymCount[$year.",".$month] = $num;
            }
        }
        $archives_list = array();
        foreach($ymCount as $k => $d) {
            $archives_list[] = $k.",".$d;
        }
        // ^^^^^ 2016-10-04
    }
    else{
        $archives_list = array();
    }
 
    $list = '';
    $list .= '<ul class="qblog_archives">';
 
//    foreach (explode("\n", $archives_list) as $line)    // delete 2016-10-04
    foreach ($archives_list as $line)                    // add 2016-10-04 , change 2017-07-27
    {
        if (rtrim($line) != '')
        {
            list($year, $month, $num) = explode(",", rtrim($line));
            // vvvvv change
            if ($month == "0") {
                $archives_url = $script.'?QBlog&amp;mode=archives&amp;date='.rawurlencode($year);
                //$list .= '<li><a href="'.$archives_url.'">'.$year.'年 ('.$num.')'.'</a></li>';
                $yearStr = $year.'年 ('.$num.')';
                $list .= <<<"eohtml"
<div class="btn-group">
    <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
        {$yearStr} <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
eohtml;
                for($m=12; $m>0; $m--) {
                    $mS = $m<10 ? "0".$m : "".$m;
                    $ymC = isset($ymCount2[$year.",".$mS]) ? $ymCount2[$year.",".$mS] : "0";
                    if ($ymC>0) {
                        $archives_url = $script.'?QBlog&amp;mode=archives&amp;date='.rawurlencode($year.$mS);
                        $list .= '<li><a href="'.$archives_url.'">'.$m."月".str_repeat("&nbsp;",8).$ymC.'件</a></li>';
                    }
                }
                $list .= <<<"eohtml"
    </ul>
</div>
eohtml;
 
            } else {
                $archives_url = $script.'?QBlog&amp;mode=archives&amp;date='.rawurlencode($year.$month);
                $list .= '<li><a href="'.$archives_url.'">'.$year.'年'.$month.'月 ('.$num.')'.'</a></li>';
            }
            // ^^^^^ change
        }
    }
    $list .= '</ul>';
    
    return $list;
}
/*
<div class="btn-group">
    <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
        action <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
        <li><a href="">action1</a></li>
        <li><a href="">action2</a></li>
        <li><a href="">action3</a></li>
    </ul>
</div>
*/
 
 
?>