WordPress Snippet

ワードプレスをカスタマイズしよう

カテゴリがたくさんある場合に、リストを絞り込み可能にする

カテゴリがたくさんあると選択するのが面倒になりますが、カテゴリの一部を入力するとその文字列が含まれるカテゴリの候補を表示してやるという試みです。

category-filter

add_action("admin_head-post-new.php", "my_filterd_categories");

function my_filterd_categories(){
?>

 <script>

// Copyright (c) 2010 Kilian Valkhof

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:

// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

(function ($) {
 // custom css expression for a case-insensitive contains()
 jQuery.expr[':'].Contains= function(a,i,m){
 return (a.textContent | | a.innerText | | "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
 };

 function listFilter(header, list) { // header is any element, list is an unordered list
 // create and add the filter form to the header
 var form= $("<form>").attr({"class":"filterform","action":"#"}),
 input= $("<input>").attr({"class":"filterinput","type":"text"});
 $(form).append(input).appendTo(header);

 $(input)
 .change( function () {
 var filter= $(this).val();
 if(filter) {
// this finds all links in a list that contain the input,
// and hide the ones not containing the input while showing the ones that do
$(list).find("label:not(:Contains(" + filter + "))").parent().slideUp();
$(list).find("label:Contains(" + filter + ")").parent().slideDown();
 } else {
$(list).find("li").slideDown();
 }
 return false;
 })
 .keyup( function () {
 // fire the above change event after every letter
 $(this).change();
 });
 }

 //ondomready
 $(function () {
 listFilter($("#category-tabs"), $("#categorychecklist"));
 });
}(jQuery));

 </script>

<?php	
}
  • https://ja.forums.wordpress.org/topic/147896?replies=5(b:@source)

[emulsion_relate_posts]