投稿

2月, 2023の投稿を表示しています

WP widget アーカイブ(年) 20230222実装コード

Quick Edit Pencil


アーカイブ(年)
<?php

// ウィジェットと同義の設定
$instance= array(
  //※'title'       => '',   // タイトル ※フックで指定する
  'dropdown'    => 1,    // ドロップダウン表示 
  'count'       => 1     // 投稿数を表示
);

// 必要があれば設定する
$args = array();

// class WP_Widget_Archives
add_filter( 'widget_title', 'hook_widget_title' );// タイトルをフック
add_filter( 'widget_archives_dropdown_args', 'hook_widget_archives_args' );// drop 月から年へ
add_filter( 'widget_archives_args', 'hook_widget_archives_args' );// flat 月から年へ
// wp_get_archives
//add_filter( 'getarchives_where', 'cat_limited_wp_get_archives' );

// クラスを実体化する
$my_archives1 = new WP_Widget_Archives();
// メソッド(関数)を起動する
$my_archives1->widget( $args, $instance );

// class WP_Widget_Archives
remove_filter( 'widget_title', 'hook_widget_title' );
remove_filter( 'widget_archives_dropdown_args', 'hook_widget_archives_args' );
remove_filter( 'widget_archives_args', 'hook_widget_archives_args' );
// wp_get_archives
//remove_filter( 'getarchives_where', 'cat_limited_wp_get_archives' );

// フック・カスタム関数
function hook_widget_title( $title ) {
    // タイトルを変更する
    $title = '';
    return $title;
}
function hook_widget_archives_args( $args ) {
    // デフォルトの月別(type=monthly)から年別のアーカイブに変更
    $args['type'] = 'yearly';
    return $args;
}

?>

<script type='text/javascript'>
/* <![CDATA[ */
(function() {
    {
        // この関数の呼び出し位置を取得し
        var scpt,s;
        scpt = document.getElementsByTagName("script");
        scpt = scpt[scpt.length-2];
        s = scpt;
    }
    // scriptタグに隣接する前の要素を取得
	var dropdown = s.previousElementSibling;
    for( var i = 0; i < dropdown.length; i++ ){
        var t = dropdown.options[i].text;
        var matches = t.match(/\d{4}/);
        for(r in matches){
            if(r==0){
                var y = matches[r];
                //console.log(y);
                y = parseInt(y);
                if (isNaN(y)) { s = "数字を入力して下さい。"; }
                else if (y > 1988) { s = "平成"+(y-1988)+"年"; }
                else if (y > 1925) { s = "昭和"+(y-1925)+"年"; }
                else if (y > 1911) { s = "大正"+(y-1911)+"年"; }
                else if (y > 1867) { s = "明治"+(y-1867)+"年"; }
                else if (y > 1864) { s = "慶応"+(y-1864)+"年"; }
                else if (y > 1863) { s = "元治"+(y-1863)+"年"; }
                else if (y > 1860) { s = "文久"+(y-1860)+"年"; }
                else if (y > 1853) { s = "安政"+(y-1853)+"年"; }
                else if (y > 1847) { s = "嘉永"+(y-1847)+"年"; }
                else { s = "1848(嘉永元年)より大きい年数を指定下さい。"; }
                //console.log(s);
                dropdown.options[i].text = t.replace(/(\d{4})/, y+'年 / '+s);
                break;
            }
        };
    }
})();
/* ]]> */
</script>

WP widget 地方地域(カスタムタグ) 20230222実装コード

Quick Edit Pencil


地方地域(カスタムタグ)
<div class="tagcloud custom-region">
<?php
$taxonomy='region';
add_filter('wp_generate_tag_cloud_data', 'custom_wp_generate_tag_cloud_data');
echo wp_tag_cloud( "taxonomy=".$taxonomy."&show_count=0&pad_counts=true" );
remove_filter( 'wp_generate_tag_cloud_data', 'custom_wp_generate_tag_cloud_data' );
 
function custom_wp_generate_tag_cloud_data($tags_data) {
    $taxonomy='region';
    // タームの親子構造の配列を取得
    $tree_terms = wp_dropdown_categories('taxonomy='.$taxonomy.'&hierarchical=1&echo=0&value_field=slug');
    // slug抜き出し配列に入れる
    preg_match_all('/value="(.*?)"/', $tree_terms, $matches);
    // タームのオブジェクトの配列で取得
    // 親子構造にタームを並べ替えと
    $order = $matches[1];
    $array1 = $tags_data;
    $sorted_array = [];
    foreach ($order as $i => $search_id) {
        foreach ($array1 as $idx => $record) {
            if ($search_id == $record[slug]) {
                $sorted_array[] = $record;
                unset($array1[$idx]);
                break;
            }
        }
    }
    $tags_data = $sorted_array;
    return $tags_data;
}
?>
</div>
外観>カスタマイズ>追加 CSS
/*SideBar PHP Code Widget タグクラウド地域*/
.custom-region a[aria-label^="近畿"],
.custom-region a[aria-label^="関東"],
.custom-region a[aria-label^="九州"],
.custom-region a[aria-label^="中部"],
.custom-region a[aria-label^="北海道"] {
	/*display:block;*/
	background: #ddd;
	/*color: white;*/
}

VBA

Quick Edit Pencil
Sub 棚卸しレイアウト図のゴンドラ分解()

    Dim ws04 As Worksheet
    Set ws04 = Worksheets("Sheet1")
    
    Dim tbl As Range
    
    Set tbl = ws04.Range("C1").CurrentRegion
    Debug.Print tbl.Count
    
    tbl.Select
    
    Dim i As Long: i = 1
    For Each c In tbl.Cells
        If Not c.Value = "" And IsNumeric(c.Value) And c.Value > 0 Then ws04.Cells(i, 1) = c.Value: i = i + 1
    Next
    
    Debug.Print i

End Sub

Sub テスト()

    Dim tbl As Range
    
    'Set tbl = ActiveCell.CurrentRegion
    'tbl.Select
    
    Set tbl = Selection
    
    Debug.Print tbl.Count

End Sub
売場案内DB.xls