-
投稿者検索結果
-
2025年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; } );
ご確認いただけますと幸いです。
お手数おかけいたしますが何卒よろしくお願い申し上げます。
♥ 0いいねをした人: 居ません2025年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(); } );
`
お手数おかけいたしますが、ご確認の程よろしくお願い申し上げます。
♥ 0いいねをした人: 居ません2025年2月6日 10:33 AM #143928返信が含まれるトピック: ランディングページ(ヘッダー・フッターあり)にパンくずリストを出したい
どこに出したいかにもよるかなと思いますが、とりあえずフックで出すことはできます。
add_filter( 'snow_monkey_template_part_render_templates/view/full', function( $html, $name ) { // 固定ページのとき if ( 'page' === $name ) { // ランディングページ(ヘッダー・フッターあり)のとき if ( 'blank-content' === \Inc2734\WP_View_Controller\Bootstrap::get_layout() ) { // パンくずを生成 ob_start(); \Framework\Helper::get_template_part( 'template-parts/common/breadcrumbs' ); $breadcrumbs = ob_get_clean(); // パンくずを出力結果にくっつける $html = $breadcrumbs . $html; } } return $html; }, 10, 2 );
表示場所やマークアップを調整したい場合は独自にテンプレートを作ったほうが管理しやすいのかなと思います。
♥ 0いいねをした人: 居ません2025年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 );
2024年12月20日 12:30 PM #143279返信が含まれるトピック: 投稿の詳細ページだけアイキャッチ画像を変更したい
投稿一覧はそのままで詳細ページでの表示だけ、ということは、あくまで「その記事の装飾としての画像を変えたい」ということだと思ったので、そのやり方を考えてみました。
※
post_thumbnail_html
で詳細ページだけ表示を変える場合、OGP 画像や関連記事などに使用される画像も変わってしまう可能性があるのでそれ以外を使ったやり方にしてみました。「アイキャッチ画像の表示」の選択肢によって対応が変わるので、一応それぞれのパターンについて考えてみました。
### 「アイキャッチ画像の位置」が「ページヘッダー」のとき
// テンプレートパーツに画像の URL を差し替えるオプションがあるのでそれを使う。 add_filter( 'snow_monkey_get_template_part_args_template-parts/common/page-header', function( $args ) { $default_image_url = get_template_directory_uri() . '/wp-content/uploads/2024/12/XXXX.jpeg'; $args['vars']['_image'] = '<img src="' . esc_url( $default_image_url ) . '" alt="' . esc_attr( get_the_title() ) . '">'; return $args; } );
### 「アイキャッチ画像の位置」が「コンテンツの上」のとき
// オプションは無いのでテンプレートパーツ自体を書き換える。 add_filter( 'snow_monkey_template_part_render_template-parts/content/eyecatch', function( $html ) { if ( ! $html ) { return $html; } $default_image_url = get_template_directory_uri() . '/wp-content/uploads/2024/12/XXXX.jpeg'; $default_image = ob_start(); ?> <div class="c-eyecatch"> <img src="<?php echo esc_url( $default_image_url ); ?>" alt="<?php echo esc_attr( get_the_title() ); ?>"> </div> <?php return ob_get_clean(); } );
2024年11月14日 3:34 AM #142706返信が含まれるトピック: WooCommerce ショッピングページ(商品リストページ)が表示されなくなった!
因みに修正した、 My Snow Monkeyのphpは以下になります。
<?php /** * Plugin name: My Snow Monkey * Description: このプラグインに、あなたの Snow Monkey 用カスタマイズコードを書いてください。 * Version: 0.2.5 * Update URI: https://snow-monkey.2inc.org * * @package my-snow-monkey * @author inc2734 * @license GPL-2.0+ */ /** * Snow Monkey bbPress Support でリダイレクトさせないようにする。 */ // add_filter( 'snow_monkey_bbpress_support_prevent_admin_access', '__return_false' ); /** * Snow Monkey 以外のテーマを利用している場合は有効化してもカスタマイズが反映されないようにする */ $theme = wp_get_theme( get_template() ); if ( 'snow-monkey' !== $theme->template && 'snow-monkey/resources' !== $theme->template ) { return; } /** * Directory url of this plugin * * @var string */ define( 'MY_SNOW_MONKEY_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); /** * Directory path of this plugin * * @var string */ define( 'MY_SNOW_MONKEY_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); /** * Display message in console.log if this plugin is enabled. */ add_action( 'wp_footer', function () { if ( is_user_logged_in() ) : ?> <script>console.log( 'My Snow Monkey plugin is active' );</script> <?php endif; } ); /** * WooCommerce が生成した各ページのページヘッダー画像としてデフォルトページヘッダー画像を使用する */ add_filter( 'snow_monkey_pre_page_header_image_url', function( $url ) { if ( class_exists( '\woocommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) ) { if ( is_singular() && has_post_thumbnail() ) { return wp_get_attachment_image_url( get_post_thumbnail_id(), 'xlarge' ); } else { $shop_page_id = wc_get_page_id( 'shop' ); if ( has_post_thumbnail( $shop_page_id ) ) { return wp_get_attachment_image_url( get_post_thumbnail_id( $shop_page_id ), 'xlarge' ); } } return get_theme_mod( 'default-page-header-image' ); } return $url; }, 11 ); /** * WooCommerce が生成した各ページにページヘッダーを表示する */ add_filter( 'snow_monkey_is_output_page_header', function( $return ) { if ( class_exists( '\woocommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) ) { return true; } return $return; }, 11 ); /** * パララックスエフェクト用の CSS, JS を読み込み * * @return void */ add_action( 'wp_enqueue_scripts', function() { if ( ! wp_script_is( 'snow-monkey-blocks/background-parallax', 'registered' ) ) { wp_enqueue_script( 'snow-monkey-blocks/background-parallax', SNOW_MONKEY_BLOCKS_DIR_URL . '/dist/js/background-parallax.js', [], filemtime( SNOW_MONKEY_BLOCKS_DIR_PATH . '/dist/js/background-parallax.js' ), true ); } } ); /** * ページヘッダーにパララックスエフェクトを反映 * * @param string $html * @param string $slug * @return string */ add_filter( 'snow_monkey_template_part_render', function( $html, $slug ) { if ( 'template-parts/common/page-header' !== $slug ) { return $html; } $html = str_replace( 'class="c-page-header"', 'class="c-page-header js-bg-parallax"', $html ); $html = str_replace( 'class="c-page-header__bgimage"', 'class="c-page-header__bgimage js-bg-parallax__bgimage"', $html ); $html = str_replace( 'class="c-container"', 'class="c-container js-bg-parallax__content"', $html ); return $html; }, 10, 2 ); /** * ショーケースウィジェットにパララックスエフェクトを反映 * * @param string $content * @param array $args * @return string */ add_filter( 'inc2734_wp_awesome_widgets_render_widget', function( $content, $args ) { if ( false === strpos( $args['widget_id'], 'inc2734_wp_awesome_widgets_showcase' ) ) { return $content; } $content = str_replace( 'wpaw-showcase ', 'wpaw-showcase js-bg-parallax ', $content ); $content = str_replace( 'wpaw-showcase__bgimage', 'wpaw-showcase__bgimage js-bg-parallax__bgimage', $content ); $content = str_replace( 'wpaw-showcase__inner', 'c-container js-bg-parallax__content wpaw-showcase__inner', $content ); return $content; }, 10, 2 ); /** * @param array active_post_types * @return array */ add_filter( 'snow_monkey_member_post_active_post_types', function( $active_post_types ) { return [ 'post', 'page' ]; // 制限機能を付与したい投稿タイプを指定 } ); /** * 再利用可能ブロックのショートカット作成 */ add_action( 'admin_menu', 'add_custom_menu' ); function add_custom_menu(){ add_menu_page( '再利用ブロック', '再利用ブロック', 'manage_options', 'edit.php?post_type=wp_block', '', 'dashicons-portfolio', 9 ); } /** * WordPressのサイドバーなどに表示されるウィジェットのタイトルを「h2」タグから他のタグ(例えば「div」タグ)へ変更する方法 */ add_filter( 'dynamic_sidebar_params', function( $params ) { $params[0]['before_title'] = str_replace( '<h2 ', '<div ', $params[0]['before_title'] ); $params[0]['after_title'] = str_replace( '/h2>', '/div>', $params[0]['after_title'] ); return $params; } ); /** * WooCommerceの商品ページに「SNS」シェアボタンを追加 */ add_filter( 'snow_monkey_get_template_part_args_templates/view/woocommerce-single-product', function( $args ) { $args['vars']['_display_top_share_buttons'] = true; // 上部に出したいとき $args['vars']['_display_bottom_share_buttons'] = true; // 下部に出したいとき return $args; } );
♥ 0いいねをした人: 居ません2024年10月4日 6:53 PM #142054返信が含まれるトピック: ”関連記事”というタイトルを変えたいです
過去のフォーラムにズバリな回答がありました。
my-snow-monkey.php
に追加してみてください。add_filter( 'snow_monkey_template_part_render', function( $html, $slug ) { if ( 'template-parts/content/related-posts' === $slug ) { return preg_replace( '|<span>.*?関連記事|ms', '<span>Related works', $html ); } return $html; }, 10, 2 );
2024年9月28日 4:14 PM #141931返信が含まれるトピック: 既存のパンくずの機能をアーカイブなどのループの中で各投稿に利用する方法
調査してみたところ、2つの要因がありました。
1つ目は、Snow Monkey のパンくずはページのクエリを参照してリストを生成しているということです。例えば、詳細ページ用のリストはページが
is_single()
のときに生成され、アーカイブページ用のリストはページがis_archive()
のときに生成されます。ループの中だとしてもページのクエリはis_arhive()
がtrue
になるので、アーカイブページ用のリストが出力されてしまう、ということになります。2つ目は、Snow Monkey のパンくずは一度生成したリストをキャッシュするようになっているので、↑の対策をしたとしてもキャッシュされたパンくずを出力してしまうために同じリストが繰り返し表示されてしまうということです。
上記2つに対して対策してみたコードが下記になります。
/** * ループのメタ情報部分にパンくずを追加する。 */ add_filter( 'snow_monkey_template_part_render_template-parts/loop/entry-summary/meta/meta', function( $html ) { query_posts( array( 'p' => get_the_ID() ) ); // これが重要。クエリを記事用に再生成する。 ob_start(); \Framework\Helper::get_template_part( 'template-parts/common/breadcrumbs' ); $breadcrumbs = ob_get_clean(); wp_reset_query(); // クエリをもとに戻す return $html . $breadcrumbs; } ); /** * パンくずを都度生成するようにする。 */ add_filter( 'snow_monkey_get_template_part_args_template-parts/common/breadcrumbs', function( $args ) { $breadcrumbs = new \Inc2734\WP_Breadcrumbs\Bootstrap(); $breadcrumbs_items = $breadcrumbs->get(); // $breadcrumbs_items = apply_filters( 'snow_monkey_breadcrumbs', $breadcrumbs_items ); // 必要ならコメントアウト $args['vars']['_items'] = $breadcrumbs_items; return $args; } );
なんとなくあんまりきれいな処理ではない気がするので、気になるようなら自作したほうが良いかもしれません…。
♥ 0いいねをした人: 居ません2024年9月27日 3:06 PM #141908返信が含まれるトピック: スノーモンキーのヘッダー部にショートコードを挿入したい
2024年9月26日 10:35 PM #141899返信が含まれるトピック: スノーモンキーのヘッダー部にショートコードを挿入したい
2024年8月24日 8:00 AM #141241返信が含まれるトピック: ドロワーナビゲーション(モバイル用)の検索窓の「検索・・・」の文字を英語「search」に変更したい
シンプルに文字列置換しているだけのコードなので、置換処理を追加すれば大丈夫だと思います。
// template-parts/nav/drawer の HTML を書き換え add_filter( 'snow_monkey_template_part_render_template-parts/nav/drawer', function( $html ) { $html = str_replace( "placeholder=\"検索 …\"", "placeholder=\"検索できます\"", $html ); $html = str_replace( "<button class=\"c-input-group__btn\">検索</button>", "<button class=\"c-input-group__btn\">Search</button>", $html ); return $html; } );
♥ 0いいねをした人: 居ません2024年8月21日 3:33 PM #141212返信が含まれるトピック: 記事タイトル下のスペースに統一注釈を入れたい
GONSY さんの書き込みに気づかずに僕もサンプルコードを書いていたので、ここで供養しておきます…(僕はページヘッダーのテンプレートパーツを置換しました)。
add_filter( 'snow_monkey_template_part_render_template-parts/content/entry/header/header', function( $html ) { return str_replace( '</header>', '<p class="notice_use_affiliate">※当サイトではアフィリエイト広告を利用しています</p></header>', $html ); } );
ページヘッダーの内側にもアクションフック用意しておいたほうが良いかも?と思いました。
2024年8月21日 1:04 PM #141210返信が含まれるトピック: 記事タイトル下のスペースに統一注釈を入れたい
ちょうど似たようなことをしていたので、参考になれば幸いです。
add_filter( 'snow_monkey_template_part_render_template-parts/content/entry-meta', function( $html ) { $html = str_replace( '</ul>', // 投稿メタ情報:<ul class="c-meta"></ul>のうしろ '</ul><p class="notice_use_affiliate">※当サイトではアフィリエイト広告を利用しています</p>', $html ); return $html; } );
2024年8月15日 7:58 AM #141146返信が含まれるトピック: モバイル用ヘッダーナビをスクロール時に隠さず固定したい
ヘッダーレイアウトは何に設定されていますか?
僕が書いたコードはヘッダーレイアウトが「中央ロゴ」の場合に適用されるものになります。フック名:snow_monkey_template_part_render_templates/layout/header/center
もし別のヘッダーレイアウトの場合はフック名が変わります。
1行:
snow_monkey_template_part_render_templates/layout/header/1row
2行:snow_monkey_template_part_render_templates/layout/header/2row
シンプル:snow_monkey_template_part_render_templates/layout/header/simple
左:snow_monkey_template_part_render_templates/layout/header/left
-
投稿者検索結果