前提・実現したいこと
初めて質問をさせていただきます。
Wordpressにて「SCHEDULE」というカスタム投稿を作成し、その記事をカレンダー形式にて表示しています。
さらに、該当の日付に記事タイトルが表示されるようにしています。
カレンダー表示の作成には下記の記事を参照して作成しました。
http://kotori-blog.com/wordpress/cpt_calendar/
(「Custom Post Type Permalinks」プラグインを使用していない場合のコードにて作成しました。)
この「SCHEDULE」というカスタム投稿にて、
・LIVE
・EVENT
というタクソノミーを指定して、分類分けをしています。
カレンダーに表示される際に、このタクソノミー毎に記事タイトルを囲っている<div>に、その記事が属するタクソノミー名のclassを付与してcssでスタイリングをしたいのですが、class付与の方法がわかりません。
どなたか、解決策のわかる方がいらっしゃいましたら、ご教授願えますと幸いです。
該当のソースコード(functions.php)
functions.php
1function my_get_calendar($cpt){ 2 ob_start(); 3 get_cpt_calendar($cpt); 4 $output = ob_get_contents(); 5 ob_end_clean(); 6 7 if(preg_match_all('@<td( id="today")?><a href="' . get_option('home') . '/([^"]*?)?post_type=([^"]*?)" title="[^"]*?">([0-9]+?)</a>@i', 8 $output, $matches)){ 9 foreach($matches[0] as $key => $match){ 10 $date = preg_replace('@/@', '', $matches[2][$key]); 11 $year = substr($date, 0, 4); 12 $month = substr($date, 4, 2); 13 $day = substr($date, 6, 2); 14 15 global $wpdb; 16 $posts = $wpdb->get_results("SELECT ID, post_title " 17 . "FROM $wpdb->posts " 18 . "WHERE YEAR(post_date) = '$year' " 19 . "AND MONTH(post_date) = '$month' " 20 . "AND DAY(post_date) = '$day' " 21 . "AND post_type = '$cpt' AND post_status = 'publish' " 22 . "ORDER BY post_date DESC" 23 ); 24 25 $link = ''; 26 foreach($posts as $post) 27 $link .= '<div><a href="'. get_permalink($post->ID) . '">' . $post->post_title . '</a></div>'; 28 $output = preg_replace('@' . preg_quote($match) . '@', $match . $link, $output); 29 } 30 } 31 return $output; 32}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/12 07:36
2019/03/12 07:47 編集