-
投稿者検索結果
-
2025年6月30日 3:53 PM #145564
返信が含まれるトピック: 特定の「任意のタクソノミーの投稿」ブロックのリンクを新規ウィンドウで開きたい。
has_category( 'demae', $post )
となっていますが$post
が存在しないためエラーがでちゃうのではないかなと思います。global $post
を入れて、グローバル変数の$post
を参照するとどうでしょうか?add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/', function( $html ) { global $post; if ( has_category( 'demae', $post ) ) { $html = str_replace( '<a', '<a target="_blank" rel="noreferrer noopener"', $html ); } return $html; } );
2025年6月30日 9:00 AM #145562返信が含まれるトピック: 特定の「任意のタクソノミーの投稿」ブロックのリンクを新規ウィンドウで開きたい。
キタジマ様
ご確認いただきありがとうございます。
やりたいことは、 「任意のタクソノミーの投稿」ブロックでカテゴリーが「demae」の場合、 新規ウィンドウで開きたいです。
下記コードを
my-snow-monkey.php
に追加しましたが、 新規ウィンドウでは開きませんでした。add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/', function( $html ) { if ( has_category( 'demae', $post ) ) { $html = str_replace( '<a', '<a target="_blank" rel="noreferrer noopener"', $html ); } return $html; } );
♥ 0Who liked: No user2025年2月19日 2:57 PM #144140返信が含まれるトピック: カスタムフィールドで表示している箇所にタグも追加したい
リプライするときに整形されるから?なのかコードが崩れているので整形してみました。
あと、コードの途中にちゃんとタグの情報が取得できているか確認するために
var_dump(...);
を追加してみました。ちゃんと取得できているならタグの情報が画面上に表示されるはずです。表示されないなら紐づけができていないか、名前が間違っている可能性がありそうです。add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function ($html) { // カスタムフィールドで設定したフィールド名を代入 $acf_name_area = get_field('name_area'); $acf_region_area = get_field('region_area'); $acf_specialty_genre = get_field('specialty_genre'); // テンプレートのh3タグの後に <div class="property-info">を追加 $acf_property_info = '</h3><div class="property-info">' . '<div class="property-body">' . '<div class="property-content">' . '<dl class="name_area"><span>【代表者名】</span> <dt>' . esc_html($acf_name_area) . '<dt></dl>' . '<dl class="region_area"><span>【地域】</span> <dt>' . esc_html($acf_region_area) . '<dt></dl>' . '<dl class="specialty_genre"><span>【取扱業務】</span> <dt>' . esc_html($acf_specialty_genre) . '<dt></dl>' . '</div>' . '</div>' . '</div>'; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( '</h3>', $acf_property_info, $html ); return $html; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( '</h3>', $acf_property_info, $html ); // 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する $post_tag_terms = get_the_terms(get_the_ID(), 'administrative_scrivener_tag'); var_dump( $post_tag_terms ); // テスト用 ob_start(); if (is_array($post_tag_terms)) { foreach ($post_tag_terms as $post_tag_term) { ?> <a href="<?php echo esc_url( get_term_link( $post_tag_term ) ); ?>"><?php echo esc_html( $post_tag_term->name ); ?></a> <?php } } $administrative_scrivener_tags = ob_get_clean(); var_dump( esc_html( $administrative_scrivener_tags ) ); // テスト用 $html = $html . $administrative_scrivener_tags; return $html; } );
2025年2月19日 2:09 PM #144139返信が含まれるトピック: カスタムフィールドで表示している箇所にタグも追加したい
キタジマ様
早速のご教授ありがとうございます。
申し訳ありません、return $html;追加と
タクソノミーnameが「administrative_scrivener_tag」の為
下記の様にpost_tagの箇所を「administrative_scrivener_tag」に変更いたしましたが表示されない様です。add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function ($html) { // カスタムフィールドで設定したフィールド名を代入 $acf_name_area = get_field('name_area'); $acf_region_area = get_field('region_area'); $acf_specialty_genre = get_field('specialty_genre'); // テンプレートのh3タグの後に <div class="property-info">を追加 $acf_property_info = ' <div class="property-info">' . ' <div class="property-body">' . ' <div class="property-content">' . ' <dl class="name_area">【代表者名】 <dt>' . esc_html($acf_name_area) . '</dt> <dt></dt> </dl> ' . ' <dl class="region_area">【地域】 <dt>' . esc_html($acf_region_area) . '</dt> <dt></dt> </dl> ' . ' <dl class="specialty_genre">【取扱業務】 <dt>' . esc_html($acf_specialty_genre) . '</dt> <dt></dt> </dl> ' . ' </div> ' . ' </div> ' . ' </div> '; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( ' ', $acf_property_info, $html ); return $html; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( ' ', $acf_property_info, $html ); return $html; // 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する ob_start(); $post_tag_terms = get_the_terms(get_the_ID(), 'administrative_scrivener_tag'); if (is_array($post_tag_terms)) { foreach ($post_tag_terms as $post_tag_term) { ?> <!--?php echo esc_html($post_tag_term->name); ?--> <!--?php <br ?--> } } $html = $html . ob_get_clean(); return $html; } );
ご確認いただけますと幸いです。
お手数おかけいたしますが何卒よろしくお願い申し上げます。
♥ 0Who liked: No user2025年2月19日 9:35 AM #144132返信が含まれるトピック: カスタムフィールドで表示している箇所にタグも追加したい
キタジマ様
早速のご教授ありがとうございます。
下記コードを追加いたしましたが表示されませんでした。
ちなみにですが、CPT UIでタクソノミーを追加して表示させている記事に紐付けしております。
記事自体の表示は、「最近の投稿」で投稿タイプを選んでおります。
add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function ($html) { // カスタムフィールドで設定したフィールド名を代入 $acf_name_area = get_field('name_area'); $acf_region_area = get_field('region_area'); $acf_specialty_genre = get_field('specialty_genre'); // テンプレートのh3タグの後に <div class="property-info">を追加 $acf_property_info = '</h3><div class="property-info">' . '<div class="property-body">' . '<div class="property-content">' . '<dl class="name_area"><span>【代表者名】</span> <dt>' . esc_html($acf_name_area) . '<dt></dl>' . '<dl class="region_area"><span>【地域】</span> <dt>' . esc_html($acf_region_area) . '<dt></dl>' . '<dl class="specialty_genre"><span>【取扱業務】</span> <dt>' . esc_html($acf_specialty_genre) . '<dt></dl>' . '</div>' . '</div>' . '</div>'; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( '</h3>', $acf_property_info, $html ); return $html; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( '</h3>', $acf_property_info, $html ); // 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する ob_start(); $post_tag_terms = get_the_terms(get_the_ID(), 'post_tag'); if (is_array($post_tag_terms)) { foreach ($post_tag_terms as $post_tag_term) { ?> <a href="<?php echo esc_url( get_term_link( $post_tag_term ) ); ?>"><?php echo esc_html( $post_tag_term->name ); ?></a> <?php } } $html = $html . ob_get_clean(); } );
`
お手数おかけいたしますが、ご確認の程よろしくお願い申し上げます。
♥ 0Who liked: No user2025年1月27日 5:24 PM #143726返信が含まれるトピック: 投稿アーカイブに投稿タグや任意の要素を追加表示したい
snow_monkey_template_part_render_<slug>
snow_monkey_pre_template_part_render_<slug>
のどちらかのフィルターフックを使用されてはどうでしょうか?/** * @param $html テンプレートパーツの出力HTML * @param $name テンプレートパーツの名前 * @param $vars テンプレートパーツのリクエスト配列 */ add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function( $html ) { $html = str_replace( '書き換え前の文字列', '書き換え後の文字列', $html ); return $html; }, 10 );
/** * @param $html テンプレートパーツの出力HTML * @param $name テンプレートパーツの名前 * @param $vars テンプレートパーツのリクエスト配列 */ add_filter( 'snow_monkey_pre_template_part_render_template-parts/loop/entry-summary/title/title', function( $html ) { return 'New HTML'; }, 10 );
2023年7月9日 8:58 PM #127900気になった点がいくつかあるので羅列します。
– 「PDFのURLを取得できず」というのは、
get_field('pdf')
で値が取れていないということですか?
–str_replace( 'src="' . get_the_post_thumbnail_url($filefiled) . '"', 'src="' . '"', $html )
だと、サムネイルの URL を空にしようとしているように見えます。(ただし、「ファイルのフィールド名を元にサムネイル URL を取得」しようとしているのでおそらくサムネイルの URL は取得できず、置換には失敗していると思います)
–template-parts/loop/entry-summary/figure/figure
を対象としてされていますが、ここにはリンクの HTML は無いと思うので、template-parts/loop/entry-summary
を対象にしてa
要素のhref
の値を書き換えるのが正しいのではと思うのですがどうでしょうか?2023年6月1日 6:18 PM #125042返信が含まれるトピック: 投稿一覧(リッチメディア)でのカテゴリー表示の条件分けをしたい。
「新しく投稿されたものに関してはカテゴリラベルのところにNewマークがつくようにする」は以下のコードを加えました。
すでに「NEW」が表示されているということですね。
私がやるとすれば、サムネイル上の「NEW」以外のカテゴリー名はCSS(display: none
)で消します。
ご提示のコードの場合、該当の要素にmy-new
がついていると思いますので、そこだけ強制的に表示させます。.c-entries .c-entry-summary__term { display: none; } .c-entries span[class*="my-new"] { display: block!important; }
カテゴリーの表示は、位置をCSSで移動させるのがちょっと嫌なので、フィルターフックsnow_monkey_template_part_render_template-parts/loop/entry-summary
で</header>
の後にreplace
を使ってリンクなしのカテゴリーを表示するようにしてあげれば、それっぽい感じになると思います。add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html ) { $category = get_the_category(); $cat_name = $category[0]->cat_name; $html = str_replace( '</header>', '</header><p class="cat_name_origin"><span>'. $cat_name. '</span></p>', $html ); return $html; } );
もっとスマートな方法もあるかと思いますが、1つの例として参考にしていただければと思います。
2023年5月22日 3:11 AM #123547返信が含まれるトピック: 任意のタクソノミーの投稿一覧にカスタムフィールドの値を表示させたい
どこまでがうまくいっていて、どこからがうまくいっていないのかがわからないので、適当なところで
var_dump()
して問題を把握すると良いかもしれませんね。add_filter( // template-parts/loop/entry-summary を書き換える 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html, $name, $vars ) { // 「シンプル」のときだけ実行 var_dump( $vars['_entries_layout'] ); if ( 'simple' === $vars['_entries_layout'] ) { // カスタムフィールドを取得して、それをもとに加工した HTML をバッファリングする // ACF や実際に保存されているデータの構造がわからないので実際の状況にあわせて書き直してください。 $course_types = get_field( 'course_type' ); var_dump( $course_types ); ob_start(); foreach ( $course_types as $course_type ) { echo '<span>' . $course_type . '</span>'; } $course_type_html = ob_get_clean(); var_dump( esc_html( $html ) ); return str_replace( '</section>', $course_type_html . '</section>', $html ); } return $html; }, 10, 3 );
2023年5月20日 4:14 AM #123481返信が含まれるトピック: 任意のタクソノミーの投稿一覧にカスタムフィールドの値を表示させたい
ありがとうございます。その後いろいろ調べながらやってみたのですが実現できず、とん挫しています。
エラーメッセージが出たので
}
return $html;を追加してエラーは出なくなったのですが表示はできずでした。
Advanced Custom Fieldsの関数get_fieldを使えばいいのでは?と思い変更したのですがそれではダメでした。※get_post_metaでも出来るようでしたが
https://lucy.ne.jp/bazubu/advanced-custom-fields-36452.html
add_filter( // template-parts/loop/entry-summary を書き換える 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html, $name, $vars ) { // 「シンプル」のときだけ実行 if ( 'simple' === $vars['_entries_layout'] ) { // カスタムフィールドを取得して、それをもとに加工した HTML をバッファリングする // ACF や実際に保存されているデータの構造がわからないので実際の状況にあわせて書き直してください。 $course_types = get_field( 'course_type' ); ob_start(); foreach ( $course_types as $course_type ) { echo '<span>' . $course_type . '</span>'; } $course_type_html = ob_get_clean(); return str_replace( '</section>', $course_type_html . '</section>', $html ); } return $html; }, 10, 3 );
♥ 0Who liked: No user2023年5月15日 11:05 AM #123138返信が含まれるトピック: 任意のタクソノミーの投稿一覧にカスタムフィールドの値を表示させたい
\Framework\Helper::get_template_part( 'template-parts/loop/entry-summary/term/term' ... );
はターム(カテゴリー等)の一覧を取得するものなので、「ここをカスタムフィールドを取得して HTML を生成・加工する」というコードに書き換えればよいのかなと思います。僕は ACF に詳しくないのと、実際に
course_type
にどのような値が入っているかがわからないのであくまでサンプルですが、だいたい下記のような感じになるのかなと思います。add_filter( // template-parts/loop/entry-summary を書き換える 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html, $name, $vars ) { // 「シンプル」のときだけ実行 if ( 'simple' === $vars['_entries_layout'] ) { // カスタムフィールドを取得して、それをもとに加工した HTML をバッファリングする // ACF や実際に保存されているデータの構造がわからないので実際の状況にあわせて書き直してください。 $course_types = get_post_meta( get_the_ID(), 'course_type' ); ob_start(); foreach ( $course_types as $course_type ) { echo '<span>' . $course_type . '</span>'; } $course_type_html = ob_get_clean(); return str_replace( '</section>', $course_type_html . '</section>', $html ); }, 10, 3 );
2023年5月11日 8:11 PM #122802返信が含まれるトピック: カスタム投稿で表示させたものを他の固定ページにも表示させたい
お世話になっております。
お忙しい中、検証いただき誠にありがとうございます。
add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function ( $html, $name ) { if ( is_page( 47 ) ) { // カスタムフィールドで設定したフィールド名を代入 $acf_image = get_field('property_image'); $acf_type = get_field('property_type'); $acf_location = get_field('property_location'); $acf_price = get_field('property_price'); $acf_land_area = get_field('property_land_area'); // テンプレートのh3タグの後に<div class='property-info'>を追加 $acf_property_info = '</h3> <div class="property-info">' . '<div class="property-img"><img src="' . esc_url($acf_image) . '" alt="Image"></div>' . '<div class="property-body">' . '<div class="property-tag">' . '<p>' . esc_html($acf_type) . '</p>' . '</div>' . '<div class="property-content">'. '<p class="location">' . esc_html($acf_location) . '</p>' . '<p class="price">' . esc_html($acf_price) . '</p>' . '<p class="land_area">' . esc_html($acf_land_area) . '</p>' . '</div>' . '</div>' . '</div>'; // テンプレートパーツのh3タグの後ろにdivタグを追加する $html = str_replace( '</h3>', $acf_property_info, $html ); } return $html; }, 10, 2 );
このように記述しました。
アイキャッチとタイトルが表示されてしまいますが、こちらはdisplay: none;で消してしまえばいけそうです。
同じページに投稿ページの最新の投稿もブロックで使っていたので
こちらもimageが出てきてしまっていますが、ページ指定で非表示にすればいけそうです。
また試してみて報告させていただきます。
アドバイスいただき、ありがとうございます。
♥ 0Who liked: No user2023年5月1日 2:56 PM #122392返信が含まれるトピック: カスタム投稿で表示させたものを他の固定ページにも表示させたい
キタジマさん、早速のご返信ありがとうございます。
カスタム投稿アーカイブの一覧部分と全く同じデザインの一覧を、特定の固定ページにも表示させたいということでしょうか?
はい、そのように表示したいです。
////////////////////////////////////// // カスタム投稿ページにカスタムフィールドを表示 ////////////////////////////////////// add_filter( 'snow_monkey_template_part_render_template-parts/content/entry/content/content', function ($html) { if (get_post_type() === 'propertys') { // カスタムフィールドで設定したフィールド名を代入 $acf_image = get_field('property_image'); $acf_type = get_field('property_type'); $acf_location = get_field('property_location'); $acf_price = get_field('property_price'); $acf_land_area = get_field('property_land_area'); $acf_property_info = '<div class="property-info">' . '<div class="property-img"><img src="' . esc_url($acf_image) . '" alt="Image"></div>' . '<div class="property-body">' . '<div class="property-tag">' . '<p>' . esc_html($acf_type) . '</p>' . '</div>' . '<div class="property-content">'. '<p class="location">' . esc_html($acf_location) . '</p>' . '<p class="price">' . esc_html($acf_price) . '</p>' . '<p class="land_area">' . esc_html($acf_land_area) . '</p>' . '</div>' . '</div>' . '</div>'; $html = $acf_property_info; } return $html; } ); //////////////////////////////////////////// // カスタム投稿のアーカイブページにカスタムフィールドを表示 //////////////////////////////////////////// add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', function ( $html ) { if( is_post_type_archive('propertys') ){ // カスタムフィールドで設定したフィールド名を代入 $acf_image = get_field('property_image'); $acf_type = get_field('property_type'); $acf_location = get_field('property_location'); $acf_price = get_field('property_price'); $acf_land_area = get_field('property_land_area'); // テンプレートのh2タグの後に <div class="property-info">を追加 $acf_property_info = '</h2><div class="property-info">' . '<div class="property-img"><img src="' . esc_url($acf_image) . '" alt="Image"></div>' . '<div class="property-body">' . '<div class="property-tag">' . '<p>' . esc_html($acf_type) . '</p>' . '</div>' . '<div class="property-content">'. '<p class="location">' . esc_html($acf_location) . '</p>' . '<p class="price">' . esc_html($acf_price) . '</p>' . '<p class="land_area">' . esc_html($acf_land_area) . '</p>' . '</div>' . '</div>' . '</div>'; // テンプレートパーツのh2タグの後ろにdivタグを追加する $html = str_replace( '</h2>', $acf_property_info, $html ); } return $html; } );
アーカイブページの見た目がこちらで(この画像の上にセクションのタイトルがあります)
・実際に他の固定ページで「最近の投稿」ブロックを使用した見た目が
↓↓↓
アイキャッチ画像を仮に抜くと上記添付画像の左上のように何も画像が表示されません。
画像に関してはアイキャッチ画像とカスタムフィールドの画像を合わせれば良いのですがテキストなどをこちらにも紐付けさせることは可能でしょうか。お忙しい中大変恐れ入りますが、よろしくお願いいたします。
♥ 0Who liked: No user2023年4月24日 2:12 PM #122077返信が含まれるトピック: 任意のタクソノミーの投稿の特定の場所にカテゴリーを表示させたい
確かに
position
調整する方式だと逆にややこしくなりそうですね…。一応フックを使ったやり方も考えてみたので共有します。add_filter( // template-parts/loop/entry-summary を書き換える 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html, $name, $vars ) { // 「シンプル」のときだけ実行 if ( 'simple' === $vars['_entries_layout'] ) { // カテゴリーラベルを取得して、各項目の最後に追加する。 ob_start(); \Framework\Helper::get_template_part( 'template-parts/loop/entry-summary/term/term', $name, array( '_context' => $vars['_context'], '_terms' => $vars['_terms'], ) ); $terms = ob_get_clean(); return str_replace( '</section>', $terms . '</section>', $html ); } return $html; }, 10, 3 );
これで画像に重なって表示されるやつ(デフォルト)と、項目の最後に追加されたやつの2箇所にタームが表示されるようになります。この状態で画像上のタームは CSS で消して、最後に追加されたタームは CSS で位置調整すると
position
だけでやる場合よりも調整しやすいかなと思います。2023年3月11日 9:19 PM #119815返信が含まれるトピック: アーカーイブページの特定の記事のテキスト色を変えたい
あ、ここデフォルトだと ID 出力されてないですね…。デフォルトで入るようにしたほうが良い気がしてきました。
とりあえず現状は無いので、追加するコードを書いてみました。add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary', function( $html ) { $html = str_replace( 'class="c-entry-summary ', 'class="c-entry-summary post__' . esc_html( get_the_ID() ) . ' ', $html ); return $html; } );
li.c-entries__item
のところには追加できなかったので、.c-entry-summary
に追加してみました。♥ 0Who liked: No user -
投稿者検索結果