' . $post->post_content;
// @$dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// $xpath = new DOMXPath($dom);
// $all_elm = $xpath->query("//h2 | //h3");
// if ($all_elm) {
// foreach ($all_elm as $elm) {
// // 元の形式([0]にタグ、[1]にテキスト)に戻す
// $table_of_contents[] = [
// $elm->nodeName,
// trim($elm->nodeValue)
// ];
// }
// }
// $response->data["toc"] = $table_of_contents;
// libxml_clear_errors();
// return $response;
// }
// add_filter("rest_prepare_hojyokincloud_report", "add_TOC", 10, 3);
// custom post type widgets の no-img を cocoon設定と同じものに設定する
function cptw_hooks_setup_func()
{
add_action(
"custom_post_type_widgets/recent_posts/widget/prepend",
"cptw_prepend_func",
10,
4
);
}
add_action("after_setup_theme", "cptw_hooks_setup_func");
function cptw_prepend_func($widget_id, $posttype, $instance, $recent_post)
{
if (
$widget_id !== "custom-post-type-recent-posts-9" &&
$widget_id !== "custom-post-type-recent-posts-12"
) {
return;
}
if (!has_post_thumbnail($recent_post)) {
echo get_entry_card_no_image_tag(1);
// 残りはjsで画像が正しく表示される様ビューの処理を加える
}
}
add_filter(
"wpp_post",
function ($html, $wpp_post, $instance) {
if ($instance["widget_id"] !== "wpp-5") {
return $html;
}
$title = esc_attr(wp_strip_all_tags($wpp_post->title));
$url = get_the_permalink($wpp_post->id);
$thumbnail = get_the_post_thumbnail($wpp_post->id, "thumb160");
$author = get_userdata($wpp_post->uid);
$author_name = $author->display_name;
$author_url = get_author_posts_url($wpp_post->uid);
$avatar = get_avatar($wpp_post->uid);
return <<
${title}
上限金額・助成額
${upper_limit}%1$s件中 %2$s%3$s件
', $total, 1 < $count ? $from + 1 . "〜" : "", $from + $count ); } elseif (strstr($url, "hojyo_detail") == true) { printf( '%2$s%3$s 件を表示/全%1$s件
', $total, 1 < $count ? $from + 1 . "〜" : "", $from + $count ); } elseif (strstr($url, "hojyokin")) { printf( '%2$s%3$s 件を表示/全%1$s件
', $total, 1 < $count ? $from + 1 . "〜" : "", $from + $count ); } else if (strstr($url, "ufaq") == true) { printf( '%2$s%3$s 件を表示/全%1$s件
', $total, 1 < $count ? $from + 1 . "〜" : "", $from + $count ); } } function getMyPostCount($post_type, $taxonomy, $terms) { $args = [ "post_type" => $post_type, "tax_query" => [ [ "taxonomy" => $taxonomy, "field" => "slug", "terms" => $terms, ], ], ]; $query = new WP_Query($args); return $query->found_posts; } /*---------------------------------------------------------------------------------------- ウィジェットに任意のパーツを設定する ・ショートコードで任意のパーツをよびだすことができる ・例:wp-content/themes/cocoon-master/area-sidebar.php をよびだす場合は以下のショートコード [template arg1="area" arg2="sidebar"] ------------------------------------------------------------------------------------------*/ function wrap_get_template_part($atts) { extract( shortcode_atts( [ "arg1" => "", "arg2" => "", ], $atts ) ); ob_start(); get_template_part($arg1, $arg2); $html = ob_get_contents(); ob_end_clean(); return $html; } add_shortcode("template", "wrap_get_template_part"); function wrap_get_template_part_for_select($atts) { // ショートコード属性の展開 extract( shortcode_atts( [ "arg1" => "", "arg2" => "", ], $atts ) ); // テンプレートの読み込みと内容の取得 ob_start(); get_template_part($arg1, $arg2); $template_content = ob_get_contents(); ob_end_clean(); // ---------------------------------------------------------------- // 【正規表現による抽出】 // ---------------------------------------------------------------- // テンプレートHTMLから以下の形式の要素を全て抽出 // 都道府県名 // $pattern: タグ全体を対象とし、href属性の値とタグの内容をキャプチャする $pattern = '/]+href="([^"]+)"[^>]*>([^<]+)<\/a>/i'; // $matches[1] にURL、 $matches[2] に表示テキスト(都道府県名)が入る preg_match_all($pattern, $template_content, $matches); $options_data = []; if (!empty($matches[1])) { // URLと表示名を組み合わせて連想配列を作成 foreach ($matches[2] as $index => $label) { $url = $matches[1][$index]; // 抽出したラベル(都道府県名)をトリム(前後の空白除去) $label = trim($label); if (!empty($label)) { $options_data[$url] = $label; } } } // ---------------------------------------------------------------- // 【select 要素の組み立て】 // ---------------------------------------------------------------- $select_name = esc_attr($arg1) . '_' . esc_attr($arg2); $output = ''; return $output; } add_shortcode("template_select", "wrap_get_template_part_for_select"); function get_template_part_for_ufaq_list($atts) { } /** * WYSIWYGエディタ(TinyMCE):カラーパレットカスタマイズ */ function custom_tiny_mce_before_init($init) { //デフォルトのカラーコード $default_colors = ' "000000", "Black", "993300", "Burnt orange", "333300", "Dark olive", "003300", "Dark green", "003366", "Dark azure", "000080", "Navy Blue", "333399", "Indigo", "333333", "Very dark gray", "800000", "Maroon", "FF6600", "Orange", "808000", "Olive", "008000", "Green", "008080", "Teal", "0000FF", "Blue", "666699", "Grayish blue", "808080", "Gray", "FF0000", "Red", "FF9900", "Amber", "99CC00", "Yellow green", "339966", "Sea green", "33CCCC", "Turquoise", "3366FF", "Royal blue", "800080", "Purple", "999999", "Medium gray", "FF00FF", "Magenta", "FFCC00", "Gold", "FFFF00", "Yellow", "00FF00", "Lime", "00FFFF", "Aqua", "00CCFF", "Sky blue", "993366", "Brown", "C0C0C0", "Silver", "FF99CC", "Pink", "FFCC99", "Peach", "FFFF99", "Light yellow", "CCFFCC", "Pale green", "CCFFFF", "Pale cyan", "99CCFF", "Light sky blue", "CC99FF", "Plum", "FFFFFF", "White" '; //追加カラーコード $custom_colors = ' "FA948E","Peachy Pink" '; /* ▼カスタマイズ内容上書き▼ */ //カラーパレット $init["textcolor_map"] = "[" . $default_colors . "," . $custom_colors . "]"; //行数設定 $init["textcolor_rows"] = 6; // return $init; } add_filter("tiny_mce_before_init", "custom_tiny_mce_before_init"); add_action("pre_get_posts", function ($query) { // 管理画面を除く && メインクエリに限定する if (!is_admin() && $query->is_main_query()) { if (is_post_type_archive("hojyo_news")) { $query->set("posts_per_page", -1); } } }); function add_custom_rewrite_rules() { add_rewrite_rule( '^ma/ma_category/([^/]+)/?$', 'index.php?ma_category=$matches[1]', 'top' ); add_rewrite_rule( '^finance/f_category/([^/]+)/?$', 'index.php?f_category=$matches[1]', 'top' ); add_rewrite_rule( '^finance/f_category/([^/]+)/page/([0-9]+)/?$', 'index.php?f_category=$matches[1]&paged=$matches[2]', 'top' ); } add_action('init', 'add_custom_rewrite_rules'); // クエリ変数を登録 function add_custom_query_vars($vars) { $vars[] = 'ma_category'; $vars[] = 'f_category'; return $vars; } add_filter('query_vars', 'add_custom_query_vars'); // リライトルールの更新 function flush_rewrite_on_activation() { add_custom_rewrite_rules(); flush_rewrite_rules(); } register_activation_hook(__FILE__, 'flush_rewrite_on_activation'); add_action('template_redirect', function() { $current_url = $_SERVER['REQUEST_URI']; // 現在のURLを取得 // category 場合に ma_category へリダイレクト if (preg_match('#^/category/(.+)/?$#', $current_url, $matches)) { $type = $matches[1]; wp_redirect(home_url('/ma_category/' . $type . '/'), 301); exit; } }); /** * WP All Import 4.7.2 バージョンでカンマ区切りの文字列を配列に変換するカスタム関数。 * * カスタムフィールドの値に以下を設定してください。{your_csv_field_name[1]} の部分は、ドラッグ&ドロップしたCSVフィールドの実際のパスに置き換えてください(例: {undefined3[1]})。 * [str_to_array_for_wpa({your_csv_field_name[1]})] * * @param string $value 変換したい、CSVフィールドのパス * @return array 変換された配列 */ function str_to_array_for_wpa( $value ) { // 値が空の場合、空の配列を返す if ( empty( $value ) ) { return array(); } // カンマで分割し、各要素の前後にある空白を除去 (trim) $array = array_map( 'trim', explode( ',', $value ) ); // 空の要素を配列から除去 (例: "値1,,値2" のような場合に空の要素ができるのを防ぐ) $array = array_filter( $array ); // 最後に、ACFのようなプラグインが期待する形式(シリアライズされた配列)に変換して返す // WP All Import のPHP関数呼び出しは、returnされた値をそのままカスタムフィールドに渡すため、 // シリアライズ処理はWP All Import側が行うことを期待しますが、 // バージョンが古いため明示的にシリアライズしています。 return serialize($array); }